Java Map Example (Add,List - Non-Generic)

package com.practice.map;

import java.util.*;
import java.util.Map.Entry;

class MapInterfaceExample {
public static void main(String args[]) {
Map map = new HashMap<>();

map.put(1, "m");
map.put(2, "a");
map.put(3, "d");
map.put(4, "d");
map.put(5, "y");

Set set = map.entrySet();

Iterator iterator =  set.iterator();
while(iterator.hasNext())
{
Map.Entry entry = (Entry) iterator.next();


System.out.println(entry.getKey()+" "+entry.getValue()+"");
}

}
}


Output :

1 m
2 a
3 d
4 d
5 y

Comments