Collections.synchronizedSortedSet(SortedSet): This method is available in java.util.Collections class of Java.
Syntax:
<E> SortedSet<E> java.util.Collections.synchronizedSortedSet(SortedSet<E> s)
This method takes one argument. This method returns a synchronized (thread-safe) sorted set backed by the specified sorted set.
Parameters: One parameter is required for this method.
s: the sorted set to be "wrapped" in a synchronized sorted set.
Returns: a synchronized view of the specified sorted set.
Exceptions: NA
Approach
Java
import java.util.Collections;import java.util.SortedSet;import java.util.TreeSet;public class CollectionssynchronizedSortedSet {public static void main(String[] args) {SortedSet<String> sortedSet = new TreeSet<String>();sortedSet.add("Hello");sortedSet.add("Java");sortedSet.add("C++");System.out.println(Collections.synchronizedSortedSet(sortedSet));}}
Output:
[C++, Hello, Java]
No comments:
Post a Comment