HashMap In Java Example
Chapter:
Collections
Last Updated:
21-07-2016 18:28:35 UTC
Program:
/* ............... START ............... */
import java.util.HashMap;
import java.util.Map;
public class JavaHashMapExample {
public static void main(String args[]){
HashMap<Integer,String> hashMap=new HashMap<Integer,String>();
hashMap.put(1,"Anson");
hashMap.put(2,"Jane");
hashMap.put(3,"Harry");
for(Map.Entry m:hashMap.entrySet()){
System.out.println(m.getKey()+" "+m.getValue());
}
}
}
/* ............... END ............... */
Output
Notes:
-
HashMap contains values based on the key. It implements the Map interface and extends AbstractMap class.
- HashMap maintains no order.
Tags
Collection, HashMap, Java