Java Collections.singletonMap(K key, V value)

Syntax

Collections.singletonMap(K key, V value) has the following syntax.

public static <K,V> Map <K,V> singletonMap(K key,    V value)

Example

In the following code shows how to use Collections.singletonMap(K key, V value) method.


/*from  w w  w  .  ja va  2s  .c o m*/
import java.util.Collections;
import java.util.Map;

public class Main {
   public static void main(String[] a){
      // create singleton map
      Map<String,String> map = Collections.singletonMap("key","Value");
      
      System.out.println("Singleton map is: "+map);
   }
}

The code above generates the following result.