Loop Map using Map.Entry in map.entrySet()
import java.util.HashMap;
import java.util.Map;
public class MapEntryTest {
public static void main(String[] args){
Map<String, String > map = new HashMap<String, String>();
//initialize map
map.put("1", "a");
map.put("2", "b");
map.put("3", "c");
// entry in entrySet
for (Map.Entry<String, String> entry : map.entrySet()){
System.out.println("key="+entry.getKey()+" value="+entry.getValue());
}
}
}
OUTPUT:
key=3 value=c
key=2 value=b
key=1 value=a
No comments:
Post a Comment