📜  如何在 hashmap 中插入重复键 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:46.855000             🧑  作者: Mango

代码示例1
Map> map = new HashMap<>();map.computeIfAbsent("key1", k -> new ArrayList<>()).add("value1");map.computeIfAbsent("key1", k -> new ArrayList<>()).add("value2"); assertThat(map.get("key1").get(0)).isEqualTo("value1");assertThat(map.get("key1").get(1)).isEqualTo("value2");