I have a Map that looks like this:
Map<String, List<Integer>> map = new TreeMap<>();
Lets say the contents of the map looks like this:
one, [-55, -55, -54, -54, -55, -54, -54, -54, -54, -55]
two, [-61, -61, -61, -61, -60, -61, -60, -61, -60, -60]
three, [-69, -69, -68, -68, -68, -69, -70, -68, -69, -69]
I have created a method called "addRandomValuesToList" that looks at a list of integers called input, takes 4 values and puts them into another list called randomValues.
public static List<Integer> addRandomValuesToList(List<Integer> input)
{
List<Integer> randomValues = new ArrayList<>();
...
return randomValues
}
I want to use the addRandomValuesToList method on all the list I have in the map so I get for example:
one, [-54, -54, -54, -54]
two, [-61, -61, -61, -61,]
three, [-69 -69, -70, -68]
I have a hard time doing this. I tried something like:
Map<String, List<Integer>> test = new TreeMap<>();
for (Map.Entry<String, List<Integer>> entry : map.entrySet()) {
newList = addRandomValuesToList(entry.getValue());
test.put(entry.getKey(), newList);
}
This causes some lists in the test map to be completely empty. Am I doing something wrong or is my approach wrong?