java - Method get of HashTable print all the elements -


i have data structure this:

hashmap<string, hashmap<string,string>> map = new hashmap<>(); 

in structure must save data in way:

low 12 1 high 22 0 low 10 1 low 11 0 

now, must print data have how first parameter "low" when .get("low") if in variable there "high" element print this. code:

private void jbutton2actionperformed(java.awt.event.actionevent evt) {                                               hashmap<string, hashmap<string,string>> map = new hashmap<>();     hashmap<string,string> map2 = new hashmap<>();     string label[];     jcheckbox casella=new jcheckbox();       if(jlist2.getmodel().getsize()>0){ //se sono state selezionate pad         for(int i=0; i<jpanel2.getcomponentcount(); i++){ //controlla se le pad hanno prode                          if( (casella=(jcheckbox) jpanel2.getcomponent(i)).isselected() ){ //si                 label=(casella.gettext()).split(" ");                 map2.put(label[4], "1");                 map.put(label[2],map2);              }             else{ //no                 label=(casella.gettext()).split(" ");                 map2.put(label[4], "0");                                     map.put(label[2], map2);              }         }           system.out.println(map.get("low"));      } 

where wrong? thanks.

you're putting map2 map should create new hashmap first time , reuse hashmap second , subsequent times.

pseudo code (untested):

label2subitems = map.get(label[2]); if (label2subitems == null) {     label2subitems = new hashmap();     map.put(label[2],label2subitems); } label2subitems.put(...); 

Comments