Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

a multi-value map, Map>, supporting multiple values per key

Map<String, List<String>> 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");
Source by www.baeldung.com #
 
PREVIOUS NEXT
Tagged: #supporting #multiple #values #key
ADD COMMENT
Topic
Name
6+2 =