Google

Thursday, September 3, 2009

Maps : How to get EntrySet

Below is an example of how to use Map.EntrySet

class MapTest{
private Map m = new HashMap();
public MapTest(){
m.put("a",1);
m.put("b",2);
m.put("c",3);
}

public void outputMap(){
for(Map.Entry e : m.entrySet()){
System.out.println(e.getKey() + " " + e.getValue());
}
}
}

call it from public static void main as follows:

new MapTest( ).outputMap( )