Java Collections unmodifiableNavigableMap() Method

The unmodifiableNavigableMap() method of Java Collections class is used to get an unmodifiable view of the specified navigable map.

Syntax

Following is the declaration of unmodifiableNavigableMap() method:

Parameter

ParameterDescriptionRequired/Optional
mIt is the navigable map for which an unmodifiable view is to be returned.Required

Returns

The unmodifiableNavigableMap() method returns an unmodifiable view of the specified navigable map.

Exceptions

NA

Compatibility Version

Java 1.8 and above

Example 1

Test it Now

Output:

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 2

Test it Now

Output:

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 3

Test it Now

Output:

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}





Latest Courses