Java Collections.emptyMap()

Syntax

Collections.emptyMap() has the following syntax.

public static final <K,V> Map <K,V> emptyMap()

Example

In the following code shows how to use Collections.emptyMap() method.


//from w  ww  .j a  v  a2 s  .  c o m
import java.util.Collections;
import java.util.Map;

public class Main {
   public static void main(String args[]) {
      // create an empty map    
      Map  emptymap = Collections.emptyMap();
      
      System.out.println("Created empty immutable map: "+emptymap); 
      
      // try to add elements
      emptymap.put("1","from java2s.com");
   }    
}

The code above generates the following result.