Android - Get value from HashMap

Paresh Mayani picture Paresh Mayani · Aug 6, 2010 · Viewed 183.7k times · Source

I have tried to search on HashMap in Android, but getting problem:

Consider this example:

HashMap<String, String> meMap=new HashMap<String, String>();
meMap.put("Color1","Red");
meMap.put("Color2","Blue");
meMap.put("Color3","Green");
meMap.put("Color4","White");

now I want to iterate it and get the value of each color and want to display in "Toast". how do I display it?

Answer

Pentium10 picture Pentium10 · Aug 6, 2010
Iterator myVeryOwnIterator = meMap.keySet().iterator();
while(myVeryOwnIterator.hasNext()) {
    String key=(String)myVeryOwnIterator.next();
    String value=(String)meMap.get(key);
    Toast.makeText(ctx, "Key: "+key+" Value: "+value, Toast.LENGTH_LONG).show();
}