Java Collection Tutorial - Java Collections .synchronizedSortedSet ( SortedSet <T> s)








Syntax

Collections.synchronizedSortedSet(SortedSet <T> s) has the following syntax.

public static <T> SortedSet <T> synchronizedSortedSet(SortedSet <T> s)

Example

In the following code shows how to use Collections.synchronizedSortedSet(SortedSet <T> s) method.

import java.util.Collections;
import java.util.SortedSet;
import java.util.TreeSet;
//  w ww. j  a  v a 2s .c om
public class Main {
   public static void main(String[] args) {
      // create set
      SortedSet<String>  set = new TreeSet<String> ();
      
      // populate the set
      set.add("from");
      set.add("java2s.com");
      set.add("tutorial");
      set.add("java");      
      
      // create a synchronized sorted set
      SortedSet<String> sorset = Collections.synchronizedSortedSet(set);
     
      System.out.println("Sorted set is :"+sorset);
   }
}

The code above generates the following result.