Most likely you came here because you know the
java.util.concurrent.ConcurrentHashMap class but couldn’t find
java.util.concurrent.ConcurrentHashSet. Sorry, this is not in the Java API yet.
The good news is that from Java 6 onwards the Collections API provides a method that allows one to obtain the
java.util.Set. Here it is:
java.util.Collections.newSetFromMap(Map, the map passed must be empty.
Let’s say you need a
Concurrent HashSet of Strings, just do the following:
Set<String> stringSet = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());