Reputation: 52800
private HashMap<String, String> mHashMap = new HashMap<String, String>();
mHashMap.put("a", "ajay");
mHashMap.put("h", "hiren");
mHashMap.put("d", "darshan");
mHashMap.put("a", "anand");
mHashMap.put("h", "harsah");
for (String key: mHashMap.keySet()) {
Log.e(key,"" + mHashMap.get(key));
}
My Result:
d - darsha
h - harshad
a - anand
I want all values from HashMap? If you have any idea related to it, then help me.
Upvotes: 0
Views: 83
Reputation: 157437
HashMap will override the value if a key for that value exists already. If you need to have more values for a key, you should use a Collection as value fro your HashMap:
private HashMap<String, Vector<String>> mHashMap = new HashMap<String, Vector<String>>();
Vector<String> tmp = new Vector<String>();
tmp.add("ajay");
tmp.add("anand");
mHashMap.put("a", tmp);
tmp = new Vector<String>();
tmp.add("hiren");
mHashMap.put("h", tmp);
and so on..
Upvotes: 1