Simple Example of HashMap class in Java .

Simple Example of HashMap class in Java .

import java.util.*;

class Test6{

public static void main(String args[]){

HashMap hm=new HashMap();

hm.put(2,"Amit");

hm.put(2,"Alok");

hm.put(1,"Pradeep");

Set set=hm.entrySet();

Iterator itr=set.iterator();

while(itr.hasNext()){

Map.Entry m=(Map.Entry)itr.next();

System.out.println(m.getKey()+" "+m.getValue());

}}}

Output: 1 Pradeep
              2 Alok
  

Read More →