VOOZH about

URL: https://www.geeksforgeeks.org/java/java-collections-emptymap-method-with-examples/

⇱ Java Collections emptyMap() Method with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Collections emptyMap() Method with Examples

Last Updated : 3 Jan, 2022

The emptyMap() method of Java Collections is a method that is used to return an empty map such that we can not change the data in map IE it is immutable.

Syntax:

public static final <Key,Value> Map<Key,Value> emptyMap() 

where, 

  • key is the key element
  • value is the value element

Parameters: This will not accept any parameters,

Return Type: This will return an empty map that is immutable.

Exceptions: It will not arise any exception.

Example 1:


Output
{}

Example 2: 

Output:

Exception in thread "main" java.lang.UnsupportedOperationException
 at java.util.AbstractMap.put(AbstractMap.java:209)
 at GFG.main(GFG.java:8)
Comment