Reverse list iteration
Iterate over a list in reverse order with a clean for-each loop.
Code Comparison
✕ Java 8
for (ListIterator<String> it =
list.listIterator(list.size());
it.hasPrevious(); ) {
String element = it.previous();
System.out.println(element);
}
✓ Java 21+
for (String element : list.reversed()) {
System.out.println(element);
}
Why the modern way wins
Natural syntax
Enhanced for loop instead of verbose ListIterator.
No copying
reversed() returns a view — no performance overhead.
Consistent API
Works on List, Deque, SortedSet uniformly.
Old Approach
Manual ListIterator
Modern Approach
reversed()
Since JDK
21
Difficulty
beginner
JDK Support
Reverse list iteration
Available
Widely available since JDK 21 LTS (Sept 2023)
How it works
The reversed() method from SequencedCollection returns a reverse-ordered view of the list. This view is backed by the original list, so no copying occurs. The enhanced for loop syntax makes reverse iteration as readable as forward iteration.
Related Documentation