Use of java.util.Collections.synchronizedSet() method

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]

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325116768&siteId=291194637