/**
* @author lautturi.com
* Java example: delete element from list using lambda in java
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
List<Integer> numbers = new ArrayList<Integer>();
for (int i = 1; i < 10; i++) {
numbers.add(i);
}
numbers.forEach(value -> System.out.print(value + " "));
numbers.remove(3); // remove the fourth element in java list
System.out.println();
numbers.forEach(value -> System.out.print(value + " "));
numbers.removeIf(x -> x==3); // remove all elements that value is 3
System.out.println();
numbers.forEach(value -> System.out.print(value + " "));
}
}Soruce:www.lautturi.comoutput:
1 2 3 4 5 6 7 8 9 1 2 3 5 6 7 8 9 1 2 5 6 7 8 9