List of usage examples for java.util Collections synchronizedSet
public static <T> Set<T> synchronizedSet(Set<T> s)
From source file:Main.java
public static void main(String[] args) { HashSet hashSet = new HashSet(); Set set = Collections.synchronizedSet(hashSet); }
From source file:Main.java
public static void main(String[] args) { TreeSet treeSet = new TreeSet(); Set set = Collections.synchronizedSet(treeSet); }
From source file:MainClass.java
public static void main(String[] a) { Set s = new HashSet(); s.add("A");//w w w.ja va2 s . c om s.add("B"); s.add("C"); s.add("D"); s.add("E"); s.add("F"); s.add("H"); Collections.synchronizedSet(s); }
From source file:Main.java
public static void main(String[] args) { // create set Set<String> set = new HashSet<String>(); // populate the set set.add("A"); set.add("B"); set.add("from"); set.add("java2s.com"); // create a synchronized set Set<String> synset = Collections.synchronizedSet(set); System.out.println("Synchronized set is :" + synset); }
From source file:MainClass.java
public static void main(String args[]) { Set simpsons = new HashSet(); simpsons.add("B"); simpsons.add("H"); simpsons.add("L"); simpsons = Collections.synchronizedSet(simpsons); synchronized (simpsons) { Iterator iter = simpsons.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); }//w w w .j a va2 s. c o m } Map map = Collections.synchronizedMap(new HashMap(89)); Set set = map.entrySet(); synchronized (map) { Iterator iter = set.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); } } }
From source file:Main.java
public static void main(String[] args) { Collection<String> c = Collections.synchronizedCollection(new ArrayList<String>()); List<String> list = Collections.synchronizedList(new ArrayList<String>()); Set<String> s = Collections.synchronizedSet(new HashSet<String>()); Map<String, String> m = Collections.synchronizedMap(new HashMap<String, String>()); }
From source file:SyncTest.java
public static void main(String args[]) { Set simpsons = new HashSet(); simpsons.add("Bart"); simpsons.add("Hugo"); simpsons.add("Lisa"); simpsons.add("Marge"); simpsons.add("Homer"); simpsons.add("Maggie"); simpsons.add("Roy"); simpsons = Collections.synchronizedSet(simpsons); synchronized (simpsons) { Iterator iter = simpsons.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); }/*from w w w.j a v a 2s . c o m*/ } Map map = Collections.synchronizedMap(new HashMap(89)); Set set = map.entrySet(); synchronized (map) { Iterator iter = set.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); } } }
From source file:Synchronization.java
public static void main(String[] args) { Collection c = Collections.synchronizedCollection(new ArrayList()); List list = Collections.synchronizedList(new ArrayList()); Set s = Collections.synchronizedSet(new HashSet()); Map m = Collections.synchronizedMap(new HashMap()); }
From source file:Main.java
final static public Set<Object> synchronizedSet() { return Collections.synchronizedSet(new HashSet<Object>(INITIAL_CAPACITY)); }
From source file:Main.java
/** * Constructs a new synchronized {@code Set} based on a {@link HashSet}. * //from w w w . j av a 2 s .c o m * @return a synchronized Set */ public static <T> Set<T> synchronizedSet() { return Collections.synchronizedSet(new HashSet<T>()); }