JavaIntermediate#collections#concurrency

HashMap vs Hashtable vs ConcurrentHashMap?

HashMap: not synchronized, allows null key/values, fast. Hashtable: synchronized (legacy), no nulls. ConcurrentHashMap: thread-safe via segmented/bucket-level locking, no null keys/values, preferred for concurrent code.

Example
Map<String,String> m1 = new HashMap<>(); m1.put(null, "ok");
Map<String,String> m2 = new ConcurrentHashMap<>(); // thread-safe, use in multi-threaded services

Related Questions

1
JavaAdvanced#collections#hashmap

How does HashMap work internally?

Open
2
JavaAdvanced#collections

What is the difference between fail-fast and fail-safe iterators?

Open
3
JavaIntermediate#java8#streams

Explain Java 8 Streams.

Open