Hey ranchers.. just wanna make sure I know pretty much all (or the main) differences between hashmap and hastables. 1o.) according to RHE book: Hashtable does not allow the null value to be stored, although it makes some efforts to support multithreaded use... 2o.) reading a post at javaranch hashtable are synchronized, hashmaps are not. any others?? thanks
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Another important difference is that Hashtable is synchronized and Hashmap is not. This is critical in knowing, because of Thread access issues. A Thread can obtain a monitor on a Hashtable without any extra coding. Any code utilizing a Hashmap that is needed to be Thread safe must provide synchronized code block when accessing Hashmap. Same thing applies when talking about Vector versus an ArrayList. The newer implementations such as Hashmap and ArrayList do not burden the programmer with the overhead of synchronization. With Vector and Hashtable you have no choice.
Howdy - I'm too lazy to follow all the links, so although I'm sure this is mentioned in the other references, I just wanted to summarize what's important for the exam: * Hashtable methods are synchronized, HashMap are not. * Hashtable does not accept null anything (so, you can't have a null key and you can't have any null values) * HashMap allows both a null key (obviously, just one) and null values And... bonus reply here Don't forget LinkedHashMap -- big difference between it and the other two (as far as the exam is concerned) is that there's no guaranteed iteration order for Hashtable and HashMap (and remember, you're not iterating over the actual Hashtable or HashMap, you're iterating over just the *values*) -- but with LinkedHashMap you get a choice of two different orderings: by insertion order, or by access order. Cheers, Kathy "too lazy to link" Sierra :roll: