VOOZH about

URL: https://www.geeksforgeeks.org/java/java-collections-unmodifiablenavigablemap%e2%80%8b-method-with-examples/

⇱ Java Collections unmodifiableNavigableMap​() Method with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Collections unmodifiableNavigableMap​() Method with Examples

Last Updated : 3 Jan, 2022

The unmodifiableMap() in java collections is used to get the unmodifiable view for the given map.

Syntax:

public static <Key,Value> Map<Key,Value> unmodifiableMap(Map<? extends Key, ? extends Key> map)

Parameters:

  • Key is the key-value type
  • Value is the value type
  • map is the input map

Return: It will return the unmodifiable view for the given map.

Exceptions: This method will not throw any kind of exception.

Example 1:


Output
{1=manoj, 2=sai, 3=ramya, 4=sravan}
{1=manoj, 2=sai, 3=ramya, 4=sravan}

Example 2: 


Output
{1=67, 2=34}
{1=67, 2=34}

Example 3: It will throw an error when we add an element to a modifiable map.

Output:

{1=67, 2=34}
Exception in thread "main" java.lang.UnsupportedOperationException
 at java.util.Collections$UnmodifiableMap.put(Collections.java:1459)
 at GFG.main(GFG.java:21)
Comment