ConcurrentHashMap.newKeySet() vs Collections.newSetFromMap()
问题 Java 8 introduced new way to obtain a concurrent Set implementation // Pre-Java-8 way to create a concurrent set Set<String> oldStyle = Collections.newSetFromMap(new ConcurrentHashMap<>()); // New method in Java 8 Set<String> newStyle = ConcurrentHashMap.newKeySet(); Is there any reason to prefer new method? Any advantages/disadvantages? 回答1: ConcurrentHashMap.newKeySet() should be somewhat more efficient as removes a single level of indirection. Collections.newSetFromMap(map) is mostly based