Flash cards
Review the key moves
What is the main idea behind Java LinkedList replaceAll() Method?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Complete the missing token from the example code.
___ java.util.LinkedList;Put the learning moves in the order that makes the concept easiest to apply.
❮ 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.replaceAll( n -> n + 1 );
System.out.println(numbers);
}
}Definition and Usage
The replaceAll() method replaces every item in a list with the result of performing an operation on the item. The operation can be defined by a lambda expression that is compatible with Java's UnaryOperator interface.
To learn about lambda expressions, see our Java Lambda Expression tutorial .
Syntax
public void replaceAll(UnaryOperator
operator )Parameter Values
| Parameter | Description |
|---|---|
| operator | Required. A UnaryOperator or lambda expression which operates on each item from the list. |