Arrays in Java are indexed from 0 to length - 1, not 1 to length, therefore you should be assign your variable accordingly and use the correct comparison operator.

Your loop should look like this:

for (int counter = myArray.length - 1; counter >= 0; counter--) {
Answer from user142162 on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-iterate-array-in-reverse-order
Java - Iterate Array in Reverse Order - GeeksforGeeks
July 23, 2025 - Example 1: The most simplest way to iterate over an array in reverse order is by using a for loop. ... // Java program to iterate array in // reverse order using for loop public class GFG { public static void main(String[] args) { // taking ...
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java list โ€บ iterating backward through a list
Iterating Backward Through a List | Baeldung
June 27, 2025 - In this quick tutorial, weโ€™ll learn about various ways in which we can iterate backward through a list in Java.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 449084 โ€บ java โ€บ enhanced-loop-iterate-reverse-order
Using enhanced for loop to iterate in reverse order ? (Java in General forum at Coderanch)
Amandeep: You'd have to go through the steps of creating another List/Array, copying the elements in reverse order to the new List/Array, then using the for each loop on that. It should be relatively easy to do.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ reverse an array in java
Reverse an Array in Java - Scaler Topics
April 28, 2024 - The basic approach to reverse an array is to iterate through the array and swap the elements of the array in such a way that it reverses the array, i.e., swap the first element with the last element, the second element with the second last element, ...
๐ŸŒ
AlgoCademy
algocademy.com โ€บ link
Looping In Reverse in Java | AlgoCademy
The iteration statement is i--, so we decrease our number by 1 every time. ... Let's print all numbers from 5 through -5 in decreasing order. Hint Look at the examples above if you get stuck. In this lesson, we will explore how to use a for loop to count backwards in Java.
๐ŸŒ
HackerEarth
hackerearth.com โ€บ practice โ€บ notes โ€บ java-iterate-over-a-list-in-the-reverse-order-example
Java: Iterate over a list in the reverse order example - Yogendra Gadilkar
With this in mind we can iterate a list in the reverse order by just using the ListIterator interface: ListIterator interface List<String> list = new ArrayList<String>(); list.add("First"); list.add("Second"); list.add("Third"); ListIterator<String> ...
Find elsewhere
๐ŸŒ
CodingTechRoom
codingtechroom.com โ€บ tutorial โ€บ java-iterating-backwards-through-a-java-list-techniques-and-examples
Java List: Iterate Backwards for Efficient Data Handling - CodingTechRoom
Q. What is the best method to iterate backwards in Java? A. The best method depends on the specific use case. For simple iterations, a standard for-loop might suffice. For more complex manipulations, a ListIterator may be more efficient. Q. Can you iterate backwards through other types of collections? A. Yes, you can iterate backwards through other collections by converting them to Lists (e.g., using Arrays.asList for arrays) or using a Collections framework.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ iterate-list-in-reverse-order-in-java
Iterate List in Reverse Order in Java - GeeksforGeeks
July 23, 2025 - // Java program to iterate List in Reverse Order import java.util.*; class GFG { public static void main(String[] args) { // For ArrayList List<String> list = new ArrayList<String>(); // Add elements to list list.add("GEEKS"); list.add("for"); list.add("geeks"); // Generate an iterator to iterate List in reverse // order ListIterator<String> gfg_itr = list.listIterator(list.size()); // hasPrevious() returns true if the list has // previous element while (gfg_itr.hasPrevious()) { // Iterate in reverse System.out.println(gfg_itr.previous()); } // print list in Reverse using for loop for (int i = list.size() - 1; i >= 0; i--) { // access elements by their index (position) System.out.println(list.get(i)); } } } Output ยท
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-program-to-traverse-through-arraylist-in-reverse-direction
Java Program to Traverse Through ArrayList in Reverse Direction - GeeksforGeeks
July 23, 2025 - We can provide the method reference System.out::println Iterator to the forEachRemaining(). ... // Traverse through ArrayList in // reverse direction Using // stream in Java import java.lang.*; import java.util.stream.*; import java.util.*; import java.io.*; class GFG { public static void main(String[] args) { // create a list List<Integer> Arlist = Arrays.asList(5, 2, 4, 8); System.out.println("Reversed : "); // create a stream // collect the elements after these operations // create a descending iterator on the stream // loop through the descending iterator // print the element Arlist.stream() .collect( Collectors.toCollection(LinkedList::new)) .descendingIterator() .forEachRemaining(System.out::println); } }
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ reversing-the-order-of-an-array-with-java-loops-95b3546e023b
Reversing the Order of an Array with Java Loops | Medium
September 7, 2025 - Arrays store values in a fixed order, but there are times when the order needs to be flipped. Walking through an array from its last element back to its first allows Java loops to produce a reversed sequence without altering the original structure.
๐ŸŒ
Software Testing Help
softwaretestinghelp.com โ€บ home โ€บ java โ€บ how to reverse an array in java: 3 methods with examples
How to Reverse An Array In Java: 3 Methods With Examples
March 24, 2020 - Using a for loop to traverse the array and copy the elements in another array in reverse order. Using in-place reversal in which the elements are swapped to place them in reverse order.
Top answer
1 of 16
165

One approach would be to reverse the whole list, but this would have O(n) performance with respect to its size. Note that the commonly-used Collections.reverse method actually reverses the original list in place, which may be an undesirable side-effect.

As a more efficient solution, you could write a decorator that presents a reversed view of a List as an Iterable. The iterator returned by your decorator would use the ListIterator of the decorated list to walk over the elements in reverse order.

For example:

Copypublic class Reversed<T> implements Iterable<T> {
    private final List<T> original;

    public Reversed(List<T> original) {
        this.original = original;
    }

    public Iterator<T> iterator() {
        final ListIterator<T> i = original.listIterator(original.size());
        
        return new Iterator<T>() {
            public boolean hasNext() { return i.hasPrevious(); }
            public T next() { return i.previous(); }
            public void remove() { i.remove(); }
        };
    }

    public static <T> Reversed<T> reversed(List<T> original) {
        return new Reversed<T>(original);
    }
}

And you would use it like:

Copyimport static Reversed.reversed;

...

List<String> someStrings = getSomeStrings();
for (String s : reversed(someStrings)) {
    doSomethingWith(s);
}

Update for Java 21

As per this answer, Java 21 includes an efficient List.reversed() method which does exactly what is requested.

2 of 16
103

For a list, you could use the Google Guava Library:

Copyfor (String item : Lists.reverse(stringList))
{
    // ...
}

Note that Lists.reverse doesn't reverse the whole collection, or do anything like it - it just allows iteration and random access, in the reverse order. This is more efficient than reversing the collection first.

To reverse an arbitrary iterable, you'd have to read it all and then "replay" it backwards.

(If you're not already using it, I'd thoroughly recommend you have a look at the Guava. It's great stuff.)

๐ŸŒ
Quora
quora.com โ€บ How-do-I-Print-reverse-of-an-array-in-java
How to Print reverse of an array in java - Quora
Answer (1 of 8): Well, what you have appears to be correct. What is it that bothers you about the code? Does it seem too simple? Well, doesnโ€™t it do precisely what you said you wanted to do? There are other ways to do it, but they would be more complicated.
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ reverse an array in java
Comprehensive Guide to Reversing an Array in Java
April 1, 2025 - Generate a new temporary array that matches the size of the original array. Iterate through the initial array and transfer the elements into the temporary array in the opposite sequence.