ArrayList.replaceAll(UnaryOperator) in Java

ArrayList.replaceAll(UnaryOperator<E>): This method is available in java.util.ArrayList class of Java.

Syntax:

void java.util.ArrayList.replaceAll(UnaryOperator<String> operator)

This method takes one argument. This method replaces each element of this list with the result of applying the operator to that element.

Parameters: One parameter is required for this method.

operator: the operator to apply to each element.

Exceptions: NA

Approach

Java

import java.util.ArrayList;

public class ArrayListreplaceAll {
    public static void main(String[] args) {
        ArrayList<String> arr = new ArrayList<>();
        arr.add("HELLO");
        arr.add("WORLD");
        arr.replaceAll(e -> e.toLowerCase());
        arr.forEach((n) -> System.out.print(n + " "));

    }
}

Output:

hello world 

No comments:

Post a Comment