Java Initialize Map With Values In One Line

[Solved] Java Initialize Map With Values In One Line | Scala - Code Explorer | yomemimo.com
Question : java 11 initialize map

Answered by : skandal

Map<String, String> emptyMap = Map.of();
Map<String, String> singletonMap = Map.of("key1", "value");
Map<String, String> map = Map.of("key1","value1", "key2", "value2");

Source : https://www.baeldung.com/java-initialize-hashmap | Last Update : Mon, 29 Jun 20

Question : java initialize map with values in one line

Answered by : fierce-fish-dmonvqawnyey

Map<String, Integer> map = Stream.of( new AbstractMap.SimpleImmutableEntry<>("idea", 1), new AbstractMap.SimpleImmutableEntry<>("mobile", 2)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

Source : https://www.baeldung.com/java-initialize-hashmap | Last Update : Wed, 16 Dec 20

Answers related to java initialize map with values in one line

Code Explorer Popular Question For Scala