I have an arraylist of Strings:
ArrayList<String> list = Arrays.asList("A", "B", "C", "D");
I would like to initialize a map HashMap<String, List<Integer>>
with the element of my list being the key and an empty list of integers being the value.
Of course there is a way to do it using a loop, but I wonder whether there is a way to do it in one line. After seeing the questions and answers in a similar question, I am aware that it is doable by:
HashMap<String, List<Integer>> bigMap = ImmutableMap.<String, List<Integer>>builder()
.put("A", new ArrayList<Integer>)
.put("B", new ArrayList<Integer>)
.put("C", new ArrayList<Integer>)
.put("D", new ArrayList<Integer>)
.build();
But that only applies to the scenario that the size of the list is small. How can I do it using stream, like the way mentioned in another question?