Add an element

Download java eBook

Example

  1. Addition
Map<Integer, String> map = new HashMap<>();
map.put(1, "First element."); 
System.out.println(map.get(1));

Output: First element.

  1. 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.

Stats

Contributors: 2
2017-07-17
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook