Skip to content

Instantly share code, notes, and snippets.

@ayush-usf
Forked from dtulig/mapsplitter.java
Last active October 19, 2020 07:27
Show Gist options
  • Save ayush-usf/caf77bf37c2f0e69f05f28dfc6580b09 to your computer and use it in GitHub Desktop.
Save ayush-usf/caf77bf37c2f0e69f05f28dfc6580b09 to your computer and use it in GitHub Desktop.
Example of using Guava's MapSplitter
final String stringToSplit = "dave:123, john:314,, matt:989";
final Map<String, String> splitKeyValues = Splitter.on(",")
.omitEmptyStrings()
.trimResults()
.withKeyValueSeparator(":")
.split(stringToSplit);
// Map Contents: {dave=123, john=314, matt=989}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment