Synchronized Set In Java Example
Chapter:
Collections
Last Updated:
21-06-2016 20:31:33 UTC
Program:
/* ............... START ............... */
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class JavaSynchronizedSetExample {
public static void main(String a[]) {
Set<String> set = new HashSet<String>();
Set<String> synchronizedSet = Collections.synchronizedSet(set);
System.out.println("Synchronized Set has been created.");
}
}
/* ............... END ............... */
Output
Synchronized Set has been created.
Notes:
-
The Set is not synchornized (not thread-safe).
- Collections.synchronizedSet() method returns a synchronized (thread-safe) set backed by the specified set.
Tags
Synchronized Set, Java, Collection