Forums Register Login

java.util package

+Pie Number of slices to send: Send
1) What is the difference between Hashtable, HashMap and HashSet?
2) What is a WeakHashMap and why is it used?
+Pie Number of slices to send: Send
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 ]
Your buns are mine! But you can have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 835 times.
Similar Threads
WA #2 ..... word association
Software Life
I Always Wanna Post Java Related Topics
Unregistered?
World Market
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:32:30.