Java Collections checkedNavigableSet() MethodThe 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 1Test it NowOutput: Type safe view of the Navigable Set is: [A1, B2, C3, D4] Example 2Test it NowOutput: The view of the Navigable Set is: [11, 22, 33, 44] Example 3Test it NowOutput: 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 provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India