1) What is the difference between Hashtable, HashMap and HashSet? Both HashMap and Hashtable associate (map) keys to values. HashMap accepts null keys and values, Hashtable does not. Hashtable is synchronized (thread safe), HashMap and HashSet are not. A HashSet contains only values (no mapping) with no duplicate values and like HashMap accepts nulls. 2) What is a WeakHashMap and why is it used? A WeakHashMap has keys that are weak references. What that means is, once the garbage collector determines that there are no reachable references, other than weak references to the key, then the key and its associated value are effectively removed from the Map. WeakHashMap, like HashMap accepts null keys and values and is not synchronized. It is used when you want the garbage collector to reclaim any object that is only referenced in the Map. It is very easy to cause a memory leak by forgetting that you have an object reference stored somewhere in a collection, the WeakHashMap insures that that won't happen. [ May 21, 2003: Message edited by: Michael Morris ]
Post by:autobot
Your buns are mine! But you can have this tiny ad:
a bit of art, as a gift, the permaculture playing cards