
package com.logicbig.example.arraylist;
import java.util.*;
public class RemoveIfExample {
public static void main(String... args) {
// Remove elements matching predicate
ArrayList<String> list = new ArrayList<>(Arrays.asList("Apple", "Banana", "Cherry", "Date"));
list.removeIf(s -> s.startsWith("B"));
System.out.println("After removeIf (startsWith B): " + list);
}
}
Output
After removeIf (startsWith B): [Apple, Cherry, Date]
JDK 25