Add an element
suggest change- Addition
Map<Integer, String> map = new HashMap<>();
map.put(1, "First element.");
System.out.println(map.get(1));
Output: First element.
- Override
Map<Integer, String> map = new HashMap<>();
map.put(1, "First element.");
map.put(1, "New element.");
System.out.println(map.get(1));
Output: New element.
HashMap
is used as an example. Other implementations that implement the Map
interface may be used as well.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents