The Javadoc of removeIf() states:

Removes all of the elements of this collection that satisfy the given predicate.

The predicate in your example is always true because you map each integer i in your list to trueby the expression: i -> true.

I added a simpler example which removes all even integers and keeps all odd integers by the predicate i % 2 == 0:

Ugly setup:

List<List<Integer>> lists = new ArrayList<List<Integer>>() {{
    add(new ArrayList<>(Arrays.asList(1,2,3,4)));
    add(new ArrayList<>(Arrays.asList(2,4,6,8)));
    add(new ArrayList<>(Arrays.asList(1,3,5,7)));
}};

Keep only odd numbers:

for (List<Integer> list : lists) {
    list.removeIf(i -> i % 2 == 0);
    System.out.println(list);
}

Output:

[1, 3]
[]
[1, 3, 5, 7]
Answer from Harmlezz on Stack Overflow
🌐
Javabrahman
javabrahman.com › java-8 › java-8-collection-removeif-method-tutorial-with-examples
Java 8 - Collection.removeIf method tutorial with examples
Knowing the specificity of purpose of the removeIf() method, and the need to remove the overhead of shifting of ArrayList elements after a removal from the midde, Java designers overrode the default implementation of removeIf() in the ArrayList (possible as ArrayList implements Collection), ...
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › arraylist removeif(): remove elements matching a condition
ArrayList removeIf(): Remove Elements Matching a Condition
August 7, 2023 - Then we use the removeIf() method to remove all even numbers from the list. ArrayList<Integer> numbers = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); numbers.removeIf(number -> number % 2 == 0); System.out.println(numbers);
🌐
Baeldung
baeldung.com › home › java › java collections › removing elements from java collections
Removing Elements from Java Collections | Baeldung
January 8, 2024 - It’s important to note that contrary to the Iterator approach, removeIf performs similarly well in both LinkedList and ArrayList. In Java 8, ArrayList overrides the default implementation – which relies on Iterator – and implements a different strategy: first, it iterates over the elements and marks the ones that match our Predicate; afterward, it iterates a second time to remove (and shift) the elements that were marked in the first iteration.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-8-arraydeque-removeif-method-in-java-with-examples
Java 8 | ArrayDeque removeIf() method in Java with Examples - GeeksforGeeks
July 11, 2025 - The removeIf() method of ArrayDeque is used to remove all those elements from ArrayDeque which satisfies a given predicate filter condition passed as a parameter to the method. This method returns true if some element are removed from the Vector.
🌐
Blogger
self-learning-java-tutorial.blogspot.com › 2018 › 07 › java8-removeif-example.html
Programming for beginners: Java8: removeIf example
July 14, 2018 - 'java.util.Collection' class provides 'removeIf' method to remove all the elements of this collection that satisfy the given predicate. This method returns true, if any element is removed from the collection.
Find elsewhere
🌐
Programiz
programiz.com › java-programming › library › arraylist › removeif
Java ArrayList removeIf()
returns true if an element is removed ... numbers.add(5); numbers.add(6); System.out.println("Numbers: " + numbers); // remove all even numbers numbers.removeIf(e -> (e % 2) == 0);; System.out.println("Odd Numbers: " + numbers); } }...
🌐
DZone
dzone.com › data engineering › data › the way of the lambda and removeif()
The Way of the Lambda and removeIf()
November 15, 2016 - This over due modernization of ... This post elaborates on the topic of Collection.removeIf() which allows for conditional removal of elements of a collection....
🌐
W3Resource
w3resource.com › java-tutorial › arraylist › arraylist_removeif.php
Java ArrayList removeIf Method - w3resource
Java Platform: Java SE 8 · Syntax: removeIf(Predicate<? super E> filter) Parameters: Return Value: true if any elements were removed · Pictorial presentation of ArrayList.removeIf() Method · Example: Java ArrayList.removeIf() Method · The ...
🌐
javaspring
javaspring.net › blog › removeif-java
Mastering `removeIf` in Java: A Comprehensive Guide — javaspring.net
It simplifies the process of removing elements from a collection based on a certain condition. Before Java 8, developers often had to use iterators and write more verbose code to remove elements that met specific criteria.
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-list-remove-methods-arraylist-remove
How To Use remove() Methods for Java List and ArrayList | DigitalOcean
September 9, 2025 - The best way to remove elements conditionally is to use the removeIf() method, which was introduced in Java 8.
🌐
W3Schools
w3schools.com › java › ref_arraylist_removeif.asp
Java ArrayList removeIf() Method
Remove all even numbers from a list: import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<Integer> numbers = new ArrayList<Integer>(); numbers.add(5); numbers.add(9); numbers.add(8); numbers.add(6); numbers.add(1); numbers.removeIf( n -> n % 2 == 0 ); System.out.println(numbers); } } Try it Yourself » ·
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-removeif-method-in-java
ArrayList removeIf() Method in Java with Examples - GeeksforGeeks
July 11, 2025 - The removeIf() method uses Java 8's Predicate functional interface to apply conditions for removing elements.
🌐
GitHub
github.com › TEAMMATES › teammates › issues › 8214
Java: Use Java 8 list.removeIf in place of Iterator · Issue #8214 · TEAMMATES/teammates
December 19, 2017 - Pre-Java 8: Iterator<String> iter = list.iterator(); while (iter.hasNext()) { String entry = iter.next(); if (condition) { iter.remove(); } } Java 8: list.removeIf(entry -> { return condition; }); There are more than 10 places where this can ...
Author   TEAMMATES
🌐
Vultr
docs.vultr.com › java › standard-library › java › util › ArrayList › removeIf
Java ArrayList removeIf() - Filter Elements Conditionally | Vultr Docs
November 13, 2024 - Apply removeIf() with a straightforward condition. java Copy · ArrayList<Integer> numbers = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)); numbers.removeIf(n -> n % 2 == 0); System.out.println(numbers); Explain Code · This code ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › remove-elements-from-a-list-that-satisfy-given-predicate-in-java
Remove elements from a List that satisfy given predicate in Java - GeeksforGeeks
January 23, 2026 - A Predicate<String> (isNotNull) checks if an element is not null. ... Example:This program shows how to remove elements from a list that meet a specific condition using Java’s removeIf() method with a Predicate.