![]() |
VOOZH | about |
The singletonMap() method of java.util.Collections class is used to return an immutable map, mapping only the specified key to the specified value. The returned map is serializable.
Syntax:
public static Map singletonMap(K key, V value)
Parameters: This method takes the following parameters as a argument:
Return Value: This method returns an immutable map containing only the specified key-value mapping.
Below are the examples to illustrate the singletonMap() method
Example 1:
Singleton map is: {key=Value}Example 2:
Singleton map is: {100=true}