Close

Java Collections - Collections.singletonMap() Examples

Java Collections Java Java API 


Class:

java.util.Collections

java.lang.Objectjava.lang.Objectjava.util.Collectionsjava.util.CollectionsLogicBig

Method:

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

Returns an immutable map, mapping only the specified key to the specified value.


Examples


package com.logicbig.example.collections;

import java.util.Collections;
import java.util.Map;

public class SingletonMapExample {

public static void main(String... args) {
Map<Integer, Integer> map = Collections.singletonMap(1, 4);
System.out.println(map);
}
}

Output

{1=4}




See Also