Wednesday 25 September 2013

HashMap Vs Hashtable

Hashtable never allow a null value neither as a key nor as a value.
HashMap allows one null key and multiple null values.

This doesnt mean that it throws an error if you insert more than a null key, it simply overwrites the value corresponding to that null key.

Eg:          
                 HashMap<String, String> hm = new HashMap<String, String>();
hm.put(null,"nulValue-1");
  System.out.println(hm.get(null));      //     prints    nulValue-1
  hm.put(null,"nulValue-2");
  System.out.println(hm.get(null));      //     prints    nulValue-2



No comments:

Post a Comment