I am trying to perform the operation using the ForEach
in Java 8 by combining the removeIf
method. But I am getting the Error.
I am not able to combine the forEach
and removeIf
in the following program:
public class ForEachIterator {
public static void main(String[] args) {
List<Integer> ints = new ArrayList<Integer>();
for (int i = 0; i < 10; i++) {
ints.add(i);
}
System.out.println(ints);
// Getting the Error in next line
ints.forEach(ints.removeIf(i -> i%2 ==0));
System.out.println(ints);
}
}