The synchronizedSortedSet() method of java.util.Collections class is used to return a synchronized (thread-safe) sorted set backed by the specified sorted set. In order to guarantee serial access, it is critical that all access to the backing sorted set is accomplished through the returned sorted set (or its views).
public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s)
Parameters: This method takes the sorted set as a parameter to be “wrapped” in a synchronized sorted set.
Return Value: This method returns a synchronized view of the specified sorted set.
Below are the examples to illustrate the synchronizedSortedSet() method
Sorted Set : [A, B, C, D] Sorted set is : [A, B, C, D]
Sorted Set : [10, 20, 30, 40] Sorted set is : [10, 20, 30, 40]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.