The following example shows the use of the java.util.Collections.synchronizedSet() method
package com.; import java.util. *; public class CollectionsDemo { public static void main(String[] args) { // create set Set<String> set = new HashSet<String>(); // populate the set set.add("TP"); set.add("IS"); set.add("FOR"); set.add("TECHIES"); // create a synchronized set Set<String> synset = Collections.synchronizedSet(set); System.out.println("Synchronized set is :"+synset); } }
Now compiling and running the above code example will produce the following results.
Synchronized set is :[FOR, IS, TECHIES, TP]