Collections checkedSortedSet() method in Java with Examples Last Updated : 08 Jun, 2021 Comments Improve Suggest changes Like Article Like Report 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.Syntax: 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 returnedtype - 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() methodExample 1: Java // Java program to demonstrate // checkedSortedSet() method // for String value import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // creating object of SortedMap<String> SortedSet<String> sset = new TreeSet<String>(); // Adding element to smap sset.add("Ram"); sset.add("Gopal"); sset.add("Verma"); // printing the sorted set System.out.println("Sorted Set: " + sset); // create typesafe view of the specified set // using checkedSortedSet() method SortedSet<String> tsset = Collections .checkedSortedSet(sset, String.class); // printing the typesafe view of specified set System.out.println("Typesafe view of sorted set: \n" + tsset); } catch (IllegalArgumentException e) { System.out.println("Exception thrown : " + e); } } } Output: Sorted Set: [Gopal, Ram, Verma] Typesafe view of sorted set: [Gopal, Ram, Verma] Example 2: Java // Java program to demonstrate // checkedSortedSet() method // for Integer value import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // creating object of SortedSet<Integer> SortedSet<Integer> sset = new TreeSet<Integer>(); // Adding element to smap sset.add(20); sset.add(30); sset.add(40); // printing the sorted set System.out.println("Sorted Set: " + sset); // create typesafe view of the specified set // using checkedSortedSet() method SortedSet<Integer> tsset = Collections.checkedSortedSet(sset, Integer.class); // printing the typesafe view of specified set System.out.println("Typesafe view of sorted set: \n" + tsset); } catch (IllegalArgumentException e) { System.out.println("Exception thrown : " + e); } } } Output: Sorted Set: [20, 30, 40] Typesafe view of sorted set: [20, 30, 40] Comment More infoAdvertise with us Next Article Collections checkedSortedSet() method in Java with Examples rohitprasad3 Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions +1 More Practice Tags : JavaJava-CollectionsMisc Similar Reads Collections checkedSortedMap() method in Java with Examples The checkedSortedMap() method of java.util.Collections class is used to return a dynamically typesafe view of the specified sorted map.The returned map will be serializable if the specified map is serializable.Since null is considered to be a value of any reference type, the returned map permits ins 2 min read Collections min() method in Java with Examples min(Collection<? extends T> coll) The min() method of java.util.Collections class is used to return the minimum element of the given collection, according to the natural ordering of its elements. All elements in the collection must implement the Comparable interface. Furthermore, all elements 4 min read Collections copy() method in Java with Examples The copy() method of java.util.Collections class is used to copy all of the elements from one list into another. After the operation, the index of each copied element in the destination list will be identical to its index in the source list. The destination list must be at least as long as the sourc 3 min read Collections.reverse() Method in Java with Examples The reverse() method of the Collections class, as the name suggests, is used to reverse the order of elements in a list. Note: It does not sort the elements, it simply reverses their current order.This class is present in java.util package so the syntax is as follows:import java.util.Collections;Col 3 min read Collections.sort() in Java with Examples java.util.Collections.sort() method is present in java.util.Collections class. It is used to sort the elements present in the specified list of Collection in ascending order. It works similar to java.util.Arrays.sort() method but it is better than as it can sort the elements of Array as well as link 5 min read Like