How to iterate over a Hashtable in JSP
I am doing stuf in JAVA as it works great. Now I need to render it in browser using JSP, following code:
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));
}
}
Any suggestions that were much appreciated.
Thanks in advance.
+1
source to share
1 answer
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());
}
}
It doesn't sort your sub-functions.
0
source to share