Skip to content

Instantly share code, notes, and snippets.

@claudioaltamura
Last active October 24, 2018 12:58
Show Gist options
  • Save claudioaltamura/0ba84ea4d0bd44519f752e4cf880731e to your computer and use it in GitHub Desktop.
Save claudioaltamura/0ba84ea4d0bd44519f752e4cf880731e to your computer and use it in GitHub Desktop.
Map string with key values to Map in Java
public class StringToMap {
public static Map<String, String> map(String str) {
return (HashMap<String, String>) Arrays
.asList(str.split(","))
.stream().map(s -> s.split("="))
.collect(Collectors.toMap(e -> e[0], e -> e[1]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment