JavaMapput

Associates the specified value with the specified key.

Syntax

map.put(key, value)

Example

Enter values below to update the example in real time.

Map
String
map
new
HashMap
put
System
out
println
get
Map<String, Integer> map = new HashMap<>();
map.put("apple", 1);
map.put("banana", 2);
System.out.println(map.get("apple")); // 1