Java Collections checkedSortedSet() MethodThe checkedSortedSet() is an inbuilt method of Java Collections class. This method is used to get a dynamically typesafe view of the specified sorted set. SyntaxFollowing is the declaration of checkedSortedSet() method: Parameter
ReturnsThe checkedSortedSet() method automatically returns a dynamically typesafe view of the specified Sorted Set in the ascending order. ExceptionsClassCastException Compatibility VersionJava 1.5 and above Example 1Test it NowOutput: Type safe view of the Set is: [Hindi100, JavaTpoint, JavaTraining, SSSIT] Example 2Test it NowOutput: The view of the Sorted Set is: [100, 200, 500, 1100] Example 3Test it NowOutput: Dynamic type safe view of Sorted Set is: [800, 1100, 5000] Exception in thread "main" java.lang.ClassCastException: Attempt to insert class java.lang.String element into collection with element type class java.lang.Integer at java.base/java.util.Collections$CheckedCollection.typeCheck(Collections.java:3038) at java.base/java.util.Collections$CheckedCollection.add(Collections.java:3081) at myPackage.CollectionCheckedSortedSetExample3.main(CollectionCheckedSortedSetExample3.java:12) Next TopicJava Collections Class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India