Created
February 22, 2018 17:02
-
-
Save bdkosher/9c33e6380b3d57b6e65db790413410b5 to your computer and use it in GitHub Desktop.
Replicating Java 9's Map.of or Guava's ImmutableMap.of in pure Java 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using a coustom keyvalue String per element of the Stream | |
Map<String, String> map = Stream.of("key1:value1", "key2:value2") | |
.collect(Collectors.toMap(str -> str.split(":")[0], // key function | |
str -> str.split(":")[1])); // value function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment