Java 8 Collection removeIf method with code samples
Java 8 has added a new method called removeIf to the Collection interface. You can use this to remove an element from a Collection in Java. In this article, I will be explaining the how this method works. Edit What does RemoveIf do? This method removes an element from the Collection that matches a particular condition. It returns a boolean value which indicates whether some values were removed or not. The condition to be checked is specified via a Predicate instance. Predicate is an in-built functional interfac e that accepts an argument of any data type and returns a boolean. You can implement it via a lambda expression . RemoveIf Integer Code Sample The following code demonstrates this method on an Integer List: public class RemoveIfDemo { public static void main(String[] args) { List<Integer> input = new ArrayList<Integer>(); input.add(5); input.add(12); input.add(17); input.add(18); input.add(25); boolean anyElementRemoved = input.remo