java - How to convert a String ( ArrayList of HashMap ) to ArrayList -


here code create hashmap , arraylist .

hashmap wbsmap = new hashmap(); arraylist<hashmap<?, string>> list = new arraylist(); arraylist<hashmap<?, string>> listchildnew = new arraylist(); 

now have stored values correspondent keys

wbsmap.put("component_"+i, bom.getstring("component")); wbsmap.put("comp_qty_"+i, bom.getstring("comp_qty").replaceall("\\s+","")); wbsmap.put("comp_unit_"+i, bom.getstring("comp_unit")); wbsmap.put("ns_left_"+i,string.valueof(ns_left)); listchildnew=generatebomstructurelatest(wbsmap,bom.getstring("component"),ns_right,string.valueof(i));     if(listchildnew.size() >0){         wbsmap.put("ns_child_"+i,listchildnew);     } wbsmap.put("ns_right_"+i,string.valueof(ns_left)); list.add(wbsmap); 

now key ns_child_ consist of arraylist of hashmap listchildnew . stored in wbsmap hashmap string object. not able iterate through value key ns_child_ . how convert arraylist of hashmap.

here how list coming in log file.

[{matl_desc_0=slug spiral casing, ns_left_0=2, comp_unit_0=pc, ns_right_0=3, comp_qty_0=1, component_0=400-110},   {ns_left_1=4, matl_desc_1=flat gasket, comp_unit_1=pc, ns_right_1=5, comp_qty_1=1, component_1=400-120},   {matl_desc_2=hexagon head screw m10, comp_unit_2=pc, component_2=400-130, ns_left_2=6, ns_right_2=7, comp_qty_2=8},   {component_3=400-140, ns_right_3=15, ns_child_3=[{component_3_child=400-141, ns_right_3_child=10, ns_left_3_child=9, comp_qty_3_child=1, matl_desc_3_child=sensor, comp_unit_3_child=pc},                                                 {component_3_child=400-142, ns_right_3_child=12, ns_left_3_child=11, comp_qty_3_child=1, matl_desc_3_child=display, comp_unit_3_child=pc},                                                 {component_3_child=400-143, ns_right_3_child=14, ns_left_3_child=13, comp_qty_3_child=1, matl_desc_3_child=casing, comp_unit_3_child=pc}], ns_left_3=8, comp_qty_3=1, matl_desc_3=revolution counter, comp_unit_3=pc},  {component_4=400-150, ns_left_4=16, ns_right_4=23, ns_child_4=[{ns_left_4_child=17, component_4_child=400-151, matl_desc_4_child=temperature sensor, ns_right_4_child=18, comp_qty_4_child=1, comp_unit_4_child=pc},                                                              {ns_left_4_child=19, component_4_child=400-152, matl_desc_4_child=display, ns_right_4_child=20, comp_qty_4_child=1, comp_unit_4_child=pc},                                                              {ns_left_4_child=21, component_4_child=400-153, matl_desc_4_child=casing, ns_right_4_child=22, comp_qty_4_child=1, comp_unit_4_child=pc}], comp_qty_4=1, matl_desc_4=thermostat, comp_unit_4=pc},  ] 

it sounds you're trying make tree structure using hashmaps. try instead of hashmap.

class hashtree {     private hashmap<string, hashtree> nodes;     private string value;      public hashtree(string value){         this.value = value;         this.nodes = new hashmap<>();     }      public hashtree(hashmap<string,string> nodes){         this.value = null;         this.nodes = new hashmap<>();          for(entry<string,string> node : nodes){             this.nodes.put(node.key,node.value);         }     }      public void put(string key, string value){         nodes.put(key, new hashtree(value));     }      public void put(string key, hashmap<string, string> childnodes){         nodes.put(key, new hashtree(childnodes));     }      // additional getters , setters } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -