hashmap递归遍历问题
下面是hashmap中的结构:
HashMap hm1=new HashMap();
hm1.put("dept_id","1");
hm1.put("dept_name","部门A");
hm1.put("parent_id","");
HashMap hm2=new HashMap();
hm2.put("dept_id","2");
hm2.put("dept_name","部门B");
hm2.put("parent_id","1");
HashMap hm3=new HashMap();
hm3.put("dept_id","3");
hm3.put("dept_name","部门C");
hm3.put("parent_id","2");
HashMap hm4=new HashMap();
hm4.put("dept_id","4");
hm4.put("dept_name","部门D");
hm4.put("parent_id","1");
HashMap hm=new HashMap();
hm.put("1",hm1);
hm.put("2",hm2);
hm.put("3",hm3);
hm.put("4",hm4);
如何使用递归或效率最高的方法将hm中的数据遍历成一棵树状结构的hmtl代码?如下图:
部门A
部门B
部门C
部门D