To reverse an int array, you swap items up until you reach the midpoint, like this:

for(int i = 0; i < validData.length / 2; i++)
{
    int temp = validData[i];
    validData[i] = validData[validData.length - i - 1];
    validData[validData.length - i - 1] = temp;
}

The way you are doing it, you swap each element twice, so the result is the same as the initial list.

Answer from 3lectrologos on Stack Overflow
🌐
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 in-place reversal in which ... interface that works on lists. ... Answer: You can use the reverse method provided by the Collections interface of Java....
🌐
GeeksforGeeks
geeksforgeeks.org › java › reverse-an-array-in-java
Reverse an Array in Java - GeeksforGeeks
July 11, 2025 - When we are working with a String array, we can use a StringBuilder and append each array element with a for loop decrementing from the array's length, then convert the StringBuilder to a string, and split back into an array.
🌐
Scaler
scaler.com › home › topics › reverse an array in java
Reverse an Array in Java - Scaler Topics
April 28, 2024 - Space Complexity - The space complexity ... array. In this method, we use the java.util.Collections.reverse(List list) function that reverses the elements of the specified List....
🌐
YouTube
youtube.com › watch
How To Reverse Arrays In JAVA | (simple & easy) - YouTube
How To Reverse Arrays In JAVA | (simple & easy)In today's video, I will be showing you how to reverse an array in Java!► Software Used:● IntelliJ IDEA: https...
Published   February 19, 2023
🌐
CodeGym
codegym.cc › java blog › java arrays › reverse an array in java
Reverse an Array in Java
January 16, 2025 - This option uses an additional ... Arrays.toString(array)); // print array // Call function to get reversed array int[] reversedArray = reverse(array); System.out.println("Reversed array : " + Arrays.toString(reversedArray)); // ...
🌐
Baeldung
baeldung.com › home › java › java array › how to reverse an array in java
How to Invert an Array in Java | Baeldung
January 8, 2024 - We’ll see a few different ways to do this using pure Java 8-based solutions – some of those mutate an existing array and some create a new one. Next, we’ll look at two solutions using external libraries — one using Apache Commons Lang and one using Google Guava. The basic idea is to reverse the order of the elements in the array.
🌐
How to do in Java
howtodoinjava.com › home › java array › reverse an array in java
Reverse an Array in Java
December 6, 2022 - Learn how to reverse or invert an array in Java. A reversed array is of equal size to the original array and contains the same items but in the reverse order.
Find elsewhere
🌐
Coderanch
coderanch.com › t › 571086 › java › Reverse-array-java
Reverse an array in java (Beginning Java forum at Coderanch)
Output of my program: 7 random digits myArray[0] = 5 myArray[1] = 14 myArray[2] = 88 myArray[3] = 18 myArray[4] = 20 myArray[5] = 8 myArray[6] = 46 myArray[7] = 100 After reversing the array myArray[0] = 100 myArray[1] = 46 myArray[2] = 8 myArray[3] = 20 myArray[4] = 20 myArray[5] = 8 myArray[6] = 46 myArray[7] = 46 And since I am not allowed to simply make a new array, the code posted below is how I am handling the reverse. Thanks again for the help. Take out some paper and a pen, and play compuiter -- follow your code, with some data, and you will quickly see what you are doing wrong. Henry · Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
🌐
freeCodeCamp
freecodecamp.org › news › java-sort-array-how-to-reverse-an-array-in-ascending-or-descending-order-with-arrays-sort-2
Java Sort Array – How to Reverse an Array in Ascending or Descending Order with Arrays.sort()
June 14, 2022 - We'll still make use of Arrays.sort();, but in this example, it'll take in two parameters – the array to be sorted and Collections.reverseOrder(). ... import java.util.Arrays; import java.util.Collections; class ArraySort { public static void main(String[] args) { Integer[] arr = { 5, 2, 1, 8, 10 }; Arrays.sort(arr, Collections.reverseOrder()); for (int values : arr) { System.out.print(values + ", "); // 10, 8, 5, 2, 1, } } }
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Reverse Array Java Example - Java Code Geeks
February 7, 2022 - In the example above, we used a temp variable to reverse the array, we swap the elements of the array. The first element is swapped with the last element. The second element id swapped with the last but one element and so on. For instance, consider array [1, 2, 3, …., n-2, n-1, n]. We swap 1 with n, 2 with n-1, 3 with n-2 and further. ... import java.util.Arrays; public class ArrayReverse { public static void main(String[] args) { int[] array = {1, 2, 3}; System.out.println("array before reverse: " + Arrays.toString(array) ); for(int i=0; i<array.length/2; i++){ int temp = array[i]; array[i] = array[array.length -i -1]; array[array.length -i -1] = temp; } System.out.println("array after reverse: " + Arrays.toString(array) ); } }
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › reverse an array in java
Comprehensive Guide to Reversing an Array in Java
April 1, 2025 - Collections.reverse(): Perfect for ArrayList instances. A new array: Generates a backward copy of the initial array. Java 8 Stream: Beneficial for functional programming styles.
🌐
PrepBytes
prepbytes.com › home › java › java program to print the elements of an array in reverse order
Reverse an Array in Java - 4 Methods with Code
April 25, 2023 - Reverse an Array by 1. Reverse Print, 2. Using Auxiliary Array, 3. Without Auxiliary Array, 4. Reverse Array Using Collections.reverse() Method
🌐
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 ...
🌐
Quora
quora.com › How-do-you-reverse-an-array-of-integers-in-Java
How to reverse an array of integers in Java - Quora
Answer: To reverse an array of integers in Java, you can use a simple loop to swap the elements of the array from both ends until you reach the middle. * Here's an example code snippet that demonstrates this: [code]public class ReverseArray ...