Create mutable collections (Map.of and List.of)

HashMap has a constructor that can take another Map, so you can create a HashMap by passing it whatever Map.of(...) produces:

HashMap<String, String> map = new HashMap<>(Map.of("k1", "v1", "k2", "v2"));

Likewise for ArrayList and List.of(...).

Leave a Comment