hashmap - Getting only one value of single key in android -


in android app, i'm trying values of single key using hash map. below code. getting 1 value "maharashtra" key "blr" , not "banglore" (in code). missing?

    hashmap<string, string> mymap = new hashmap<string, string>();     mymap.put("ind", "india");     mymap.put("tn", "tamilnadu" + " how");      mymap.put("blr","bangalore");      mymap.put("blr","maharashtra");     set<entry<string,string>> set = mymap.entryset();      (map.entry<string, string> me : set) {         if(me.getkey().equals("blr")){             system.out.println(me.getvalue());      }  } 

first of all: can't. stated here:

public v put(k key, v value) 

associates specified value specified key in map. if map contained mapping key, old value replaced.

please read: http://docs.oracle.com/javase/7/docs/api/java/util/hashmap.html

second: if using key, value structure shouldn't think of ever having duplicate keys, defeats purpose of key, value collection.

a simple solution use hashmap<string, list<string>> instead of hashmap<string, string>. storing values in list<string>.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -