/*
Hash Map allows null for both key and values.
we will see that in this program.
Author; itsafiz@gmail.com
*/
import java.util.*;
import java.util.Iterator;
class HashMapTest
{
public static void main(String[]args)
{
HashMap<String, Integer> name = new HashMap<String,Integer>();
name.put("one",1);
name.put("two",2);
name.put("three",3);
name.put("four",null);
// printing all the keys ....
Set<String> keys = name.keySet(); // returns entire key set in the Map
Iterator item = keys.iterator();
while(item.hasNext())
{
String s = item.next().toString();
System.out.println(s+" = "+name.get(s));// get() method returns value
}
}
}
0 Comments