The checkedSortedSet() method of java.util.Collections class is used to return a dynamically typesafe view of the specified sorted set.
The returned sorted set will be serializable if the specified sorted set is serializable.
Since null is considered to be a value of any reference type, the returned sorted set permits insertion of null elements whenever the backing sorted set does.
public static SortedSet checkedSortedSet(SortedSet s, Class type)
Parameters: This method takes the following argument as a parameter:
- s – the sorted set for which a dynamically typesafe view is to be returned
- type – the type of element that s is permitted to hold
Return Value: This method returns a dynamically typesafe view of the specified sorted set.
Below are the examples to illustrate the checkedSortedSet() method
Sorted Set: [Gopal, Ram, Verma] Typesafe view of sorted set: [Gopal, Ram, Verma]
Sorted Set: [20, 30, 40] Typesafe view of sorted set: [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.