This is not true. In my version, the JDK HashMap.size()has difficulty O(1), whereas ConcurrentHashMap.size()at best, you have to iterate over segments. In the worst case scenario, it blocks all segments, which can be quite an expensive operation in a multi-threaded scenario.
Of course, this is rather another question. The answer largely depends on how many threads access the map, and what exactly they do.
source
share