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.
People also ask

Does Java provide a built-in method to reverse an array?
Javaโ€™s standard libraries do not include a direct method for reversing primitive arrays. However, you can convert the array to a List, by using Collections.reverse(), then convert it back, which works for arrays of object references.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ reverse an array in java
Comprehensive Guide to Reversing an Array in Java
What is the best way to reverse an array in Java?
An in-place approach using two pointers is often considered the best because it swaps elements from both ends of the array without extra memory, runs in O(n) time, and is straightforward to implement.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ reverse an array in java
Comprehensive Guide to Reversing an Array in Java
How do I reverse an array in Java 8 using streams?
You can convert the array to a stream, collect it into a list, and then use Collections.reverse(). Alternatively, map the array to an IntStream (for primitives) or Stream (for objects), then reverse the collection after accumulation.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ reverse an array in java
Comprehensive Guide to Reversing an Array in Java
๐ŸŒ
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 - Learn how to reverse an array in Java using 3 simple methods with examples. Methods like using loops, Collections, and built-in methods with code explanations.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ reverse an array in java
Reverse an Array in Java - Scaler Topics
April 28, 2024 - In the above example, the array A1 contains the elements [1, 2, 3, 4, 5]. On reversing this array, we get an array A2, i.e., [5, 4, 3, 2, 1]. Note how the element 3, present in the middle of the array, remains in place.
๐ŸŒ
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)); // ...
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ reverse an array in java
Comprehensive Guide to Reversing an Array in Java
April 1, 2025 - Array Reversal is the process of taking an array (a list of elements) and flipping the order of its contents. Let's take an example, if you have an array(1,2,3,4,5), reversing it results: in (5,4, 3,2,1).
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] ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ javaexamples โ€บ java arrays reverse example
Java Arrays Reverse Example
September 1, 2008 - Following example reverses an array list by using Collections.reverse(ArrayList)method. import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[] args) { ArrayList arrayList = new ArrayList(); arrayList.add("A"); arrayList.add("B"); arrayList.add("C"); arrayList.add("D"); arrayList.add("E"); System.out.println("Before Reverse Order: " + arrayList); Collections.reverse(arrayList); System.out.println("After Reverse Order: " + arrayList); } }
๐ŸŒ
PREP INSTA
prepinsta.com โ€บ home โ€บ dsa with java โ€บ reverse an array in java
Reverse an array in Java | PrepInsta
October 7, 2022 - 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]+" "); } }
๐ŸŒ
Java Code Geeks
examples.javacodegeeks.com โ€บ home โ€บ java development โ€บ core java
Reverse Array Java Example - Java Code Geeks
February 7, 2022 - You can reverse an array by converting an array to ArrayList and then reverse the ArrayList or use the Apache Commons ArrayUtils.reverse().
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-iterate-array-in-reverse-order
Java - Iterate Array in Reverse Order - GeeksforGeeks
July 23, 2025 - // Java Program to iterate over an array // in reverse order using enhanced for loop import java.util.*; public class Main { public static void main(String[] args) { // Array initialization Integer[] arr = {10, 20, 30, 40, 50}; // Reversing ...
๐ŸŒ
Java67
java67.com โ€บ 2016 โ€บ 10 โ€บ 3-ways-to-reverse-array-in-java-coding-interview-question.html
[Solved] 3 Examples to reverse an Array in Java - Example Tutorial | Java67
This is another simple way to reverse an array in Java is by first converting the array to List and then using the Collections.reverse() method to reverse the ArrayList. This method takes a List and reverses the element in linear time. You should use this approach if you need to reverse an array in your project. You can reverse int, String, or any type of array by using this method. Let's see an example of reversing a String array in Java:
๐ŸŒ
Javatpoint
javatpoint.com โ€บ java-program-to-print-the-elements-of-an-array-in-reverse-order
Java Program to print the elements of an array in reverse order - Javatpoint
Java Program to print the elements of an array in reverse order - Java Program to print the elements of an array in reverse order on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree, graph, pattern, string etc.
๐ŸŒ
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 - Time Complexity: The time complexity of this approach is O(N) as we have to traverse the array. Space Complexity (Auxiliary Space): The auxiliary space used is O(1) as we have not used any extra space. In Java, the method reverse() in the Class Collections is used to reverse collections like ...
๐ŸŒ
STechies
stechies.com โ€บ reverse-array-java
3 Methods to Reverse an Array in Java
This particular method of array reverse in Java converts the given array into an ArrayList and then utilizes the Collections.reverse() method that takes up the items in the list and reverses the elements in linear time. Arrays of int, string or other types can be reversed with the help of this method.The following example ...
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2017 โ€บ 09 โ€บ java-program-to-reverse-the-array
Java Program to reverse the Array
On the second * iteration i is ... last. */ j = i - 1; i = 0; scanner.close(); while(i<j) { temp = number[i]; number[i] = number[j]; number[j] = temp; i++; j--; } System.out.print("Reversed array: "); for(i=0; i<counter; i++) { System.out.print(number[i]+ " "); } } }...
๐ŸŒ
Java67
java67.com โ€บ 2016 โ€บ 01 โ€บ java-program-to-reverse-array-in-place.html
How to Reverse an Array in place in Java? Example Solution | Java67
In the last section, I have explained to you the logic or algorithm to reverse an array in place, now is the time to convert that algorithm into pseudo-code and then real code in Java. You will also calculate the time and space complexity of our solution, which is often required in Interviews as well as in the real world to meet your performance SLA. So, let's see an example of how you can reverse an array of String in Java in place.