How to apply some changes to each element in List<List<>> structure using Java 8 approach

Viewed 109

I have some structure like List<List<Double>> listOfDoubles I need to transform it to List<List<Integer>> listOfInteger. I wrote code without using Java 8. And it looks like:

List<List<Integer>> integerList = new ArrayList<>();
for (int i = 0; i < doubleList.size(); i++) {
    for (Double doubleValue : doubleList.get(i)) {
        integerList.get(i).add(doubleValue.intValue());
    }
}

I tried to replace second for by foreach but can't because i should be final. How to write this code using Java 8 approach?

3 Answers
Related