Javatpoint Logo
Javatpoint Logo

Java Collections checkedSortedSet() Method

The checkedSortedSet() is an inbuilt method of Java Collections class. This method is used to get a dynamically typesafe view of the specified sorted set.


Following is the declaration of checkedSortedSet() method:


Parameter Description Required/Optional
s It is the sorted set for which a dynamically typesafe view is to be returned. Required
type It is the type of element that s is permitted to hold. Required


The checkedSortedSet() method automatically returns a dynamically typesafe view of the specified Sorted Set in the ascending order.



Compatibility Version

Java 1.5 and above

Example 1

Test it Now


Type safe view of the Set is: [Hindi100, JavaTpoint, JavaTraining, SSSIT]

Example 2

Test it Now


The view of the Sorted Set is: [100, 200, 500, 1100]

Example 3

Test it Now


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(
	at java.base/java.util.Collections$CheckedCollection.add(
	at myPackage.CollectionCheckedSortedSetExample3.main(

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA