bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java LinkedList removeIf() Method

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java LinkedList removeIf() Method?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ java.util.LinkedList;
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The removeIf() method removes all elements from this list for which a condition is satisfied.
Definition and Usage
Java LinkedList removeIf() Method

❮ LinkedList Methods

Example

import java.util.LinkedList;
public class Main {
  public static void main(String[] args) {
    LinkedList<Integer> numbers = new LinkedList<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);
  }
}

Definition and Usage

The removeIf() method removes all elements from this list for which a condition is satisfied. The condition can be defined by the return value of a lambda expression that is compatible with the test() method of Java's Predicate interface.

To learn about lambda expressions, see our Java Lambda Expression tutorial .

Syntax

public boolean removeIf(Predicate
condition )

Parameter Values

ParameterDescription
conditionRequired. A Predicate object or lambda expression which tests an item from the list.

Technical Details

Returns:true if any items were removed from the list, false otherwise.

Previous

Java LinkedList removeFirst() Method

Next

Java LinkedList removeLast() Method