This is a classic question. ArrayList and HashMap are not synchronized, while Vector and HashTable. Therefore, you should use a HashTable if you do not define mutexes very carefully.
In other words, methods, for example. HashTable ensures that no other thread will work with HashTable at any given time. If you use a HashMap, you will have to do it manually, making sure that you synchronize the HashMap before calling the method.
Update: @Gray statement. It seems like wrapping a HashMap with Collections.synchronizedMap (new HashMap ()) is the way to go.
EDIT: The other posters answered better than me. My answer, however, sparked an interesting discussion about using the soon obsolete Vector, Stack, Hashtable, and Dictionary classes, so I leave the question here as a chapter for the comments below. Thanks guys!
source share