PDA

View Full Version : Java API question



andrew222
March 7th, 2009, 05:04 AM
Does anyone know what the differences are between ConcurrentHashMap and HashMap in the Java API...

shadylookin
March 7th, 2009, 05:14 AM
looks like concurrentHashMap is thread safe and HashMap is not.

Most data structures in java have a thread safe type and one that is not.

DocForbin
March 7th, 2009, 06:40 AM
Use ConcurrentHashMap if your app is multi-threaded and it's possible to have multiple threads operating on the map at the same time (e.g. one enumerating it while another is updating it).

andrew222
March 7th, 2009, 07:53 PM
Thank you...that was a recent interview question...