![]() |
VOOZH | about |
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:
Return: It will return the unmodifiable view for the given map.
Exceptions: This method will not throw any kind of exception.
Example 1:
{1=manoj, 2=sai, 3=ramya, 4=sravan}
{1=manoj, 2=sai, 3=ramya, 4=sravan}Example 2:
{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)