Skip to content

Commit 9f5b52d

Browse files
authored
Update Map.ofEntries usage (#3151)
Looks like each entry should be wrapped in its own `Map.entry(K,V)` before being passed to `Map.ofEntries()` Change: From `Map<String, Integer> temperatures = Map.ofEntries(Map.entry("Mon", 30, "Tue", 28, "Wed", 32));` To `Map<String, Integer> temperatures2 = Map.ofEntries( Map.entry("Mon", 30), Map.entry("Tue", 28), Map.entry("Wed", 32) );`
1 parent d8e92d5 commit 9f5b52d

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

concepts/maps/about.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ Another common way to create maps is to use [Map.of][map-of-javadoc] or [Map.ofE
145145
Map<String, Integer> temperatures = Map.of("Mon", 30, "Tue", 28, "Wed", 32);
146146

147147
// or using Map.ofEntries
148-
Map<String, Integer> temperatures2 = Map.ofEntries(Map.entry("Mon", 30, "Tue", 28, "Wed", 32));
148+
Map<String, Integer> temperatures2 = Map.ofEntries(
149+
Map.entry("Mon", 30),
150+
Map.entry("Tue", 28),
151+
Map.entry("Wed", 32)
152+
);
149153
```
150154

151155
Unlike `HashMap`, they populate the map upfront and become read-only once created.

0 commit comments

Comments
 (0)