Java Collections unmodifiableNavigableMap() MethodThe unmodifiableNavigableMap() method of Java Collections class is used to get an unmodifiable view of the specified navigable map. SyntaxFollowing is the declaration of unmodifiableNavigableMap() method: Parameter
ReturnsThe unmodifiableNavigableMap() method returns an unmodifiable view of the specified navigable map. ExceptionsNA Compatibility VersionJava 1.8 and above Example 1Test it NowOutput: Initial Map: {key1=Java, key2=Android, key3=JavaScript} Unmodifiable Navigable Map: {key1=Java, key2=Android, key3=JavaScript} Unmodifiable Navigable Map after adding: {key1=Java, key2=Android, key3=JavaScript, key4=JavaTpoint} Example 2Test it NowOutput: Initial Unmodifiable Navigable Map: {1=one, 2=two} Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.Collections$UnmodifiableMap.put(Collections.java:1453) at myPackage.CollectionsUnmodifiableNavigableMapExample2.main(CollectionsUnmodifiableNavigableMapExample2.java:10) Example 3Test it NowOutput: Initial map: {1=1001, 2=1002, 3=1003, 4=1004, 5=1005} Unmodifiable navigable map after remove(4, 1004): {1=1001, 2=1002, 3=1003, 5=1005} 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