HashMap does not allow duplicate keys however it allows to have duplicate values. HashSet permits to have a single null value. HashMap permits single null key and any number of null values.
import java.util.*;
public class hashmapeg2{
public static void main(String args[]){
HashMap<Integer,String> map=new HashMap<Integer,String>();//Creating HashMap
map.put(1,"Cat"); //Put elements in Map
map.put(2,"Dog");
map.put(3,"Markhor");
map.put(4,"Peacock");
map.put(1,"Leopard");
System.out.println("Iterating Hashmap...");
for(Map.Entry m : map.entrySet()){
System.out.println(m.getKey()+" "+m.getValue());
}
}
}