Created
October 26, 2015 11:20
-
-
Save malte0811/d628d12e932ec0cd256c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tmp; | |
import java.util.Collections; | |
import java.util.Iterator; | |
import java.util.Set; | |
import java.util.concurrent.ConcurrentHashMap; | |
public class Main { | |
public static void main(String[] args) { | |
Set<String> s = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>()); | |
s.add("1"); | |
s.add("2"); | |
s.add("3"); | |
s.add("4"); | |
Iterator<String> it = s.iterator(); | |
System.out.println(it.next()); | |
s.remove("4"); | |
System.out.println(it.next()); | |
System.out.println(it.next()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
as you said, every set is backed by a list or map ... the one it is created from of course XD .. but the default implementation for most sets is base of a non-concurrent safe list or hashmap, therefore i was curious if your aproach is properly CME safe and you proved me wrong :D thank you for teaching me a lesson