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 - An array can be reversed using ... array to traverse and store the elements in reverse order. Using the in-built reverse() method of the Collections framework....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ program-to-reverse-an-array
Array Reverse - GeeksforGeeks
Time Complexity: O(n), the reverse method has linear time complexity. Auxiliary Space: O(1) Additional space is not used to store the reversed array, as the in-built array method swaps the values in-place.
Published ย  August 8, 2025
Find elsewhere
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ reverse an array in java
Comprehensive Guide to Reversing an Array in Java
April 1, 2025 - Transforming the List back into an array: After the reversal, we iterate through the list and transfer the elements back into the original array. ... This method is beneficial when you wish to leverage the capabilities of the Collections framework, which provides built-in functions such as 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 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. 1. Collections.reverse() API The easiest way to reverse the array is to use the existing APIs built โ€ฆ
๐ŸŒ
STechies
stechies.com โ€บ reverse-array-java
3 Methods to Reverse an Array in Java
This interesting class is used in association with the java.util.Arrays class for playing with object and primitive arrays in Java. The API provides easy-to-use overloaded methods for reversing different types of arrays in Java โ€“ be it int, ...
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ java arrays โ€บ reverse an array in java
Reverse an Array in Java
January 16, 2025 - So here we have looked at 5 different ways to reverse an array. Option 3, which uses the Collections framework, is probably the best method to use since Collections.reverse is an already existing, tried and tested, Java function. Of course the other options can be used, especially while learning, but generally standard methods, if they exist, are the best as they are usually highly optimized and tested.
๐ŸŒ
YouTube
youtube.com โ€บ watch
How To Reverse An Array In JAVA | FREE DSA Course in JAVA | Lecture 63 - YouTube
We are covering simple java operations on arrays.In this program, we will learn how to reverse an array.For example, we have an array, 1, 5, 6, 79, 80, 60, 2...
Published ย  January 31, 2023
๐ŸŒ
PREP INSTA
prepinsta.com โ€บ home โ€บ dsa with java โ€บ reverse an array in java
Reverse an array in Java | PrepInsta
October 7, 2022 - import java.util.Scanner; public class Main { static void reverseRecursive(int arr[], int start, int end) { if (start >= end) return; int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; // recursive call to swap arr[start+1] & arr[end-1] reverseRecursive(arr, start + 1, end - 1); } public static void main(String args[]) { int arr[] = {10, 20, 30, 40, 50}; int n=arr.length; int start = 0, end = n-1; reverseRecursive(arr, start, end); for(int i=0; i<n; i++) System.out.print(arr[i]+" "); } }
๐ŸŒ
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 ...
๐ŸŒ
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.
๐ŸŒ
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) ); } }