Java SE API
List.reversed()
Java 21 reverse-ordered view. Supported view mutations write through; whether changes made directly to the backing list are visible depends on implementation. The ArrayList example demonstrates observed behavior. Not an independent copy.
Formal Syntax & Structure
java syntaxjava
default List<E> reversed()Return Value
List<E>
Reverse-ordered view.
Working Example
Example Snippetjava
import java.util.*;public class Main {
public static void main(String[] args) { List<String> original = new ArrayList<>(List.of("A", "B")); List<String> reverse = original.reversed(); List<String> snapshot = new ArrayList<>(reverse); original.addLast("C"); System.out.println(reverse); System.out.println(snapshot); System.out.println(original.getFirst()); }}