Java Collection Tutorial - Java Collections.emptyMap()


Collections.emptyMap() has the following syntax.

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


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

//  w w  w . j a v  a  2 s  . com
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

The code above generates the following result.