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

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
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
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
🌐
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 ...
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › program-to-reverse-an-array
Array Reverse - GeeksforGeeks
#include <stdio.h> #include <stdlib.h> void reverseArray(int arr[], int n) { // Temporary array to store elements // in reversed order int temp[n]; // Copy elements from original array // to temp in reverse order for(int i = 0; i < n; i++) temp[i] = arr[n - i - 1]; // Copy elements back to original array for(int i = 0; i < n; i++) arr[i] = temp[i]; } int main() { int arr[] = { 1, 4, 3, 2, 6, 5 }; int n = sizeof(arr) / sizeof(arr[0]); reverseArray(arr, n); for(int i = 0; i < n; i++) printf("%d ", arr[i]); return 0; } ... import java.util.Arrays; class GfG { static void reverseArray(int[] arr) {
Published   August 8, 2025
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Reverse Array Java Example - Java Code Geeks
February 7, 2022 - You can also use Apache Commons ArrayUtils.reverse() method to reverse any array in Java. This method is overloaded to reverse byte, short, long, int, float, double and String 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.
Find elsewhere
🌐
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.
🌐
Baeldung
baeldung.com › home › java › java list › reverse an arraylist in java
Reverse an ArrayList in Java | Baeldung
April 3, 2025 - The Java standard library has provided the Collections.reverse method to reverse the order of the elements in the given List. This convenient method does in-place reversing, which will reverse the order in the original list it received.
🌐
Blogger
javahungry.blogspot.com › 2017 › 06 › how-to-reverse-array-in-java-with-example.html
How to Reverse Integer or String Array in Java with Example | Java Hungry
import java.util.*; public class ReverseArray { public static void main (String[] args) throws java.lang.Exception { // Given input array String[] inputArray = {"India","USA","Germany","Australia"}; // Print array before reverse System.out.println("Array without reverse : " + Arrays.toString(inputArray)); // Calling method to swap elements reverseArray(inputArray); } public static void reverseArray(String[] arr) { // Converting Array to List List<String> list = Arrays.asList(arr); // Reversing the list using Collections.reverse() method Collections.reverse(list); // Converting list back to Arr
🌐
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....
🌐
CodeGym
codegym.cc › java blog › java arrays › reverse an array in java
Reverse an Array in Java
January 16, 2025 - Array before reverse : [1, 4, 9, 16, 25] Array after reverse : [25, 16, 9, 4, 1] In Java, the reverse method, which is part of the existing Collections framework, can be used to reverse an array.
🌐
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
October 3, 2016 - Yes, you can reverse the array by writing your own function, which loops through the array and swaps elements until the array is sorted. That's actually should be your first approach to coding interviews.
🌐
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 - Each call to data[index] shifts from the start of the array to the right position. Nothing gets copied during this read, the runtime just calculates the offset and fetches the value. Reversing depends on the same principle, except the offsets are taken in the opposite order. It helps to remember that Java arrays store their length as part of their structure.
🌐
PREP INSTA
prepinsta.com › home › dsa with java › reverse an array in java
Reverse an array in Java | PrepInsta
October 7, 2022 - System.out.println(Arrays.stream(arr).boxed().sorted(Collections.reverseOrder()).collect(Collectors.toList())); //java 8 · Log in to Reply ·
🌐
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
All you need to do is a loop over the array from start to the middle element and swap the first element to the last, second element to the second last until you reach the middle element.