代码之家  ›  专栏  ›  技术社区  ›  Vinayak Bevinakatti

如何在JSP中迭代哈希表

  •  1
  • Vinayak Bevinakatti  · 技术社区  · 17 年前

    我正在用JAVA做一个stuf,因为它工作得很好。。现在我需要它使用JSP显示在浏览器中,下面是我的代码。。

    Hashtable<String, Hashtable<String, Integer>> hash =
                categoryCountManager.getFunctionWithSubFunctionCount(1L);
    
            setCategoryDetails(categoryCountManager.getFunctionWithSubFunctionCount(1L));
    
            //count.setFunction()
            System.out.println("Hash Size==>"+hash.size());  
    
    
            Set<String> functions = hash.keySet();
    
            for(String fun : functions){
                System.out.println("***************************");                      
                System.out.println(fun);
                System.out.println("***************************");
                Hashtable<String, Integer> obj = hash.get(fun);
    
    
                Vector<String> v = new Vector<String>(obj.keySet());
                Collections.sort(v);
    
                for(String str : v){                            
                    System.out.println("#"+str+"-"+obj.get(str));
                    }
    
    
    
                }
    

    非常感谢您的任何建议。。

    1 回复  |  直到 17 年前
        1
  •  0
  •   Bombe    17 年前
    for (Entry<String, Hashtable<String, Integer>> functionEntry : hash.entrySet()) {
        System.out.println("***************************");                      
        System.out.println(fun);
        System.out.println("***************************");
        for (Entry<String, Integer> subfunction : functionEntry.getValue().entrySet()) {
            System.out.println("#" + subfunction.getKey() + "-" + subfunction.getValue());
        }
    }
    

    不过,这并没有对您的子功能进行排序。

    推荐文章