I have a List<List<Double>>
. I want to filter rows on the basis of an index i.e. if value of an element at index 4 is less than 0.2 then, skip that row? The resultant List<List<Double>>
should be smaller or same as the input one.
You can use Stream.filter
. Note you have to select the rows which you want to take, not the rows which you want to skip:
List<List<Double>> input = ...;
List<List<Double>> result = input.stream()
.filter(row -> row.get(4) >= 0.2)
.collect(Collectors.toList());
An alternative to the Stream API would be in-place modification using Collection.removeIf
:
List<List<Double>> input = ...;
input.removeIf(row -> row.get(4) < 0.2);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments