Java tutorial
import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) { Map<Integer, String> map = new HashMap<>(); for (int i = 0; i < 10; i++) { map.putIfAbsent(i, "val" + i); } map.forEach((id, val) -> System.out.println(val)); map.merge(9, "val9", (value, newValue) -> value.concat(newValue)); System.out.println(map.get(9)); // val9 map.merge(9, "concat", (value, newValue) -> value.concat(newValue)); System.out.println(map.get(9)); // val9concat } }