Online Java Compiler By
JavaTpoint.com
import java.util.*; class TestGenerics2{ public static void main(String args[]){ Map
map=new HashMap
(); map.put(1,"vijay"); map.put(4,"umesh"); map.put(2,"ankit"); //Now use Map.Entry for Set and Iterator Set
> set=map.entrySet(); Iterator
> itr=set.iterator(); while(itr.hasNext()){ Map.Entry e=itr.next();//no need to typecast System.out.println(e.getKey()+" "+e.getValue()); } }}
Output