Skip to content

Instantly share code, notes, and snippets.

@bdkosher
Created February 22, 2018 17:02
Show Gist options
  • Save bdkosher/9c33e6380b3d57b6e65db790413410b5 to your computer and use it in GitHub Desktop.
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
// 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