Java Collections checkedNavigableSet() Method21 Mar 2025 | 2 min read The checkedNavigableSet() is an inbuilt method of Java Collections class. This method is used to get a dynamically typesafe view of the specified Navigable Set. If any attempt of inserting an element whose value has the wrong type, it will through an immediate ClassCastException. SyntaxFollowing is the declaration of checkedNavigableSet() method: Parameter
ReturnsThe checkedNavigableSet() method returns a dynamically typesafe view of the specified Navigable Set. ExceptionsClassCastException Compatibility VersionJava 1.8 and above Example 1Output: Type safe view of the Navigable Set is: [A1, B2, C3, D4] Example 2Output: The view of the Navigable Set is: [11, 22, 33, 44] Example 3Output: Type safe view of the Navigable Set1 is: [A, B] Type safe view of the Navigable Set2 is: [11, 12] Exception in thread "main" java.lang.ClassCastException: java.base/java.lang.Integer cannot be cast to java.base/java.lang.String at java.base/java.lang.String.compareTo(String.java:124) at java.base/java.util.TreeMap.put(TreeMap.java:566) at java.base/java.util.TreeSet.add(TreeSet.java:255) at myPackage.CollectionCheckedNavigableSetExample3.main(CollectionCheckedNavigableSetExample3.java:21) Next TopicJava Collections Class |
We request you to subscribe our newsletter for upcoming updates.

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