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
🌐
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.
Discussions

Why is there no Arrays.reverse() ?
Reversing an array is a common task Is it? I've never done it in my career as a java dev, mostly because reversing an array is the same thing as iterating through it backwards, which saves space and time. I'm assuming you're using an array instead of a list because those things matter, right? More on reddit.com
🌐 r/learnjava
17
40
September 20, 2020
How am I supposed to reverse the elements of an array?

this sounds like homework haha

easy way: make a 2nd array the same length as the original one, then use the for loop you mentioned

cooler way: reverse an array without making a 2nd array

More on reddit.com
🌐 r/learnprogramming
5
0
February 26, 2021
I tried to add inputs to an array in reverse and printed it. Literal GIBBERISH came out
Literal GIBBERISH came out [I@19bb089b That's far from gibberish and far from random. That's the class name and hashcode of the object. This is exactly what you told the program to do. You told the program to print the array list, not the elements of the array list. When just plain calling .println on an object, the .toString() method is implicitly called. Yet, if the .toString() method has not been overridden in a child class, the parent's method (up to the very root of the Java Object hierarchy Object) is used. The implementation for .toString() in the Object class is return getClass().getName() + '@' + Integer.toHexString(hashCode()) In order to print the elements of the array list you need to iterate over the elements and print each element individually. Another alternative is to use Arrays.toString(int[] a) More on reddit.com
🌐 r/javahelp
4
3
July 8, 2019
Sorting an int[] arr in reverse order
just sort it from largest to smallest instead of smallest to largest. There are tons of sorting algos, but the easiest is bubble sort. More on reddit.com
🌐 r/javahelp
22
7
July 1, 2022
🌐
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.
🌐
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 ...
Find elsewhere
🌐
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....
🌐
Coderanch
coderanch.com › t › 571086 › java › Reverse-array-java
Reverse an array in java (Beginning Java forum at Coderanch)
March 21, 2012 - 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)
🌐
Quora
quora.com › How-do-you-reverse-an-array-in-place-in-Java
How to reverse an array in place in Java - Quora
Answer (1 of 9): To reverse an array there are few steps involved:- 1. We have to find index of 1st and last , then 2nd and 2nd last .. so on. 2. Swap each of those index values. 3. You have to iterate only half the size of array and each iteration you swap the values of 1st and last, then 2nd a...
🌐
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
🌐
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.
🌐
Sololearn
sololearn.com › en › Discuss › 2918817 › reversing-array-in-java
Reversing array in Java | Sololearn: Learn to code for FREE!
November 6, 2021 - I want to get a reversing array public String getArrayReverse(int[] array) { String result = "" System.out.println("Original array: "); for (int i = 0; i < array.length; i++) { System.out.print(array[i] + " "); } System.out.println("Array in reverse order: "); //Loop through the array in reverse order for (int i = array.length-1; i >= 0; i--) { System.out.print(array[i] + " "); } ... import java.util.Scanner; public class Program { public static void main(String[] args) { String str = new Scanner(System.in).nextLine(); System.out.println(new StringBuilder(str).reverse()); } } // Keep learning & happy coding :D https://code.sololearn.com/c2YhalWK4iqL/#java
🌐
PREP INSTA
prepinsta.com › home › dsa with java › reverse an array in java
Reverse an array in Java | PrepInsta
October 7, 2022 - Here, in page we will discuss various method for reversing the array. Different methods are : ... import java.util.Scanner; public class Main { public static void main(String args[]) { int arr[] = {10, 20, 30, 40, 50}; int n=arr.length; for(int i=n-1; i>=0; i--) System.out.print(arr[i]+" "); } }
🌐
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, } } }
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › reverse
Array.prototype.reverse() - JavaScript | MDN
The reverse() method is generic. It only expects the this value to have a length property and integer-keyed properties. Although strings are also array-like, this method is not suitable to be applied on them, as strings are immutable.
🌐
LeetCode
leetcode.com › problems › reverse-string
Reverse String - LeetCode
The input string is given as an array of characters s. You must do this by modifying the input array in-place [https://en.wikipedia.org/wiki/In-place_algorithm] with O(1) extra memory.
🌐
How to do in Java
howtodoinjava.com › home › java array › reverse an array in java
Reverse an Array in Java
December 6, 2022 - Learn to reverse an array using for-loop, swapping items, Collections API and also the Apache Commons's ArrayUtils class.
🌐
W3Schools
w3schools.com › jsref › jsref_reverse.asp
W3Schools.com
The reverse() method reverses the order of the elements in an array.