The HashMap class uses a hash table to implement the Map interface. This allows the execution time of basic operations, such as get( ) and put( ), to remain constant even for large sets.
import java.util.*; class DemoHashMap{ public static void main(String args[]){ HashMaphm=new HashMap (); hm.put(100,"A"); hm.put(101,"B"); hm.put(102,"C"); for(Map.Entry m:hm.entrySet()){ System.out.println(m.getKey()+" "+m.getValue()); } } }
102 C 100 A 101 B
HashSet contains only values whereas HashMap contains entry(key and value).