Skip to content

Instantly share code, notes, and snippets.

@Pozo
Created August 20, 2017 18:35
Show Gist options
  • Save Pozo/13e782aab6c0e99d3e677cd4d4da36d4 to your computer and use it in GitHub Desktop.
Save Pozo/13e782aab6c0e99d3e677cd4d4da36d4 to your computer and use it in GitHub Desktop.
static void lazyMap() {
Map<String, List<Integer>> map = new HashMap<>();
final ArrayList<Integer> integers = new ArrayList<>();
integers.add(32);
map.put("aaa", integers);
final String key = "aaa";
final int value = 2;
if (!map.containsKey(key)) {
ArrayList<Integer> listOfValues = new ArrayList<>();
listOfValues.add(value);
map.put(key, listOfValues);
} else {
map.get(key).add(value);
}
System.out.println(map);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment