StringBuilder::reverse

Simply iterate the array, and replace each entry with its reverse. You can use a StringBuilder to reverse a String, calling StringBuilder.reverse.

Like,

public static void reverse(String[] array) {
    for (int i = 0; i < array.length; i++) {
        array[i] = new StringBuilder(array[i]).reverse().toString();
    }
}

And then to test it

public static void main(String[] args) {
    String arr[] = { "abc", "def" };
    reverse(arr);
    System.out.println(Arrays.toString(arr));
}

See this code run live at IdeOne.com.

[cba, fed]

Answer from Elliott Frisch on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ reverse-an-array-in-java
Reverse an Array in Java - GeeksforGeeks
July 11, 2025 - // Java Program to reverse an array // using loop import java.util.Arrays; public class Geeks { public static void main(String[] args) { int[] arr = {1, 2, 3, 4, 5}; // Swap elements from start to end for (int i = 0; i < arr.length / 2; i++) { int t = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = t; } System.out.println("" + Arrays.toString(arr)); } } Output ยท
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 48864692 โ€บ how-to-reverse-string-array-by-using-loop-in-java
How to reverse String Array by using loop in java - Stack Overflow
... void reverse1(){ for(int i = x[0].length()-1; i >= 0; i--){ y=y + x[0].charAt(i); System.out.print(y); } } Note that I have changed the for loop statement as well so it iterates over the String at index 0, not the 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
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ java array โ€บ reverse an array in java
Reverse an Array in Java
December 6, 2022 - The same swapping goes on in the for-loop until we hit the middle of the array, at this time the array has been reversed. String[] array = {"A", "B", "C", "D", "E"}; for (int i = 0; i < array.length / 2; i++) { String temp = array[i]; array[i] = array[array.length - 1 - i]; array[array.length - 1 - i] = temp; } System.out.println(Arrays.toString(array)); //[E, D, C, B, A]
๐ŸŒ
Hero Vired
herovired.com โ€บ learning-hub โ€บ blogs โ€บ reverse-a-string-in-java
How to Reverse a String in Java Using for Loop | Hero Vired
A simple way to reverse a string in Java is using the while loop. You can move your cursor to get the string length or iterate via the string index and get rid of the loop.
๐ŸŒ
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 - Answer: There are three methods to reverse an array in Java. Using a for loop to traverse the array and copy the elements in another array in reverse order.
Top answer
1 of 5
5

StringBuilder::reverse

Simply iterate the array, and replace each entry with its reverse. You can use a StringBuilder to reverse a String, calling StringBuilder.reverse.

Like,

public static void reverse(String[] array) {
    for (int i = 0; i < array.length; i++) {
        array[i] = new StringBuilder(array[i]).reverse().toString();
    }
}

And then to test it

public static void main(String[] args) {
    String arr[] = { "abc", "def" };
    reverse(arr);
    System.out.println(Arrays.toString(arr));
}

See this code run live at IdeOne.com.

[cba, fed]

2 of 5
1

Stream

The Answer by Elliott Frisch is correct and robust, and should be accepted.

In addition, for fun, here is a version of that code using streams rather than the conventional for loop. I am not claiming this is better.

I do not know of a way for a stream of an array to affect that array. So instead here I make and return a fresh array.

public static String[] reverse( String[] array ) {
    Objects.requireNonNull( array , "Received null argument where an array of `String` was expected. Message # b5c03336-4b9e-4735-a054-16e43aac059e.") ;
    
    Stream< String > stream = Arrays.stream( array ) ;
    String[] result =
            stream
            .map( ( String s ) -> new StringBuilder( s ).reverse().toString() )
            .toArray(String[]::new) 
    ;
    
    return result ;
}

Usage.

    String arr[] = { "abc" , "def" , "mask" } ;
    String arr2[] = Ideone.reverse( arr ) ;
    
    System.out.println( Arrays.toString( arr ) ) ;
    System.out.println( Arrays.toString( arr2 ) ) ;

See that code run live at IdeOne.com.

[abc, def, mask]

[cba, fed, ksam]

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 - This effectively reverses the order of the array elements. You can implement it using a simple for loop that runs up to the midpoint of the array, Changing elements at i and length - i - 1.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ reverse-a-string-in-java
Reverse a String in Java - GeeksforGeeks
For Loop: For simplicity and complete manual control over the reversal process. StringBuilder/StringBuffer: Efficient and concise with built-in reverse() methods. Character Array: When working with individual characters or for manual control.
Published ย  October 14, 2025
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ reverse an array in java
Reverse an Array in Java - Scaler Topics
April 28, 2024 - Using the in-built reverse() method of the Collections framework. Using StringBuilder.append() method in case of string arrays. Using for loop to simply view the elements in reverse order.
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ how to reverse a string in java: 12 best methods
How to Reverse a String in Java: 12 Best Methods
May 5, 2025 - How to Reverse a String in Java? 1. Using toCharArray() 2. Using StringBuilder 3. Using While Loop/For Loop 4. Converting a String to Bytes 5. Using ArrayList
Address ย  5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
๐ŸŒ
Javatpoint
javatpoint.com โ€บ reverse-string-using-array-in-java
Reverse String Using Array in Java - Javatpoint
Reverse String Using Array in Java with java tutorial, features, history, variables, programs, operators, oops concept, array, string, map, math, methods, examples etc.
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2805778 โ€บ how-to-reverse-a-string-in-java
How to reverse a string in java | Sololearn: Learn to code for FREE!
public class Program { public static ... reversed += arr[i]; } System.out.println(reversed); } } Use the for loop starting from the last item in the array and work backwards....
๐ŸŒ
LogicMojo
logicmojo.com โ€บ reverse-a-string-in-java
Reverse a String in Java- Logicmojo
The for loop iterates until the string number zero is reached. ... import java.lang.*; import java.io.*; import java.util.*; class reversestring { public static void main(String[] arg) { // declaring variable String stringinput = "Logicmojo"; ...
๐ŸŒ
Javatpoint
javatpoint.com โ€บ reverse-a-string-using-a-for-loop-in-java
Reverse a String Using a For Loop in Java - Javatpoint
Reverse a String Using a For Loop in Java with java tutorial, features, history, variables, programs, operators, oops concept, array, string, map, math, methods, examples etc.
๐ŸŒ
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 - A loop walks through the original array from the last index down to the first, while another counter runs forward through the new array. Each assignment moves one value into the reversed structure, leaving the original untouched. public class ...
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ random โ€บ different ways to reverse a string in java
Different Ways to Reverse a String in Java
February 1, 2023 - The first method is by using the ... loop, where we convert the original string to a char array and iterate through the array in reverse order, assigning the corresponding characters to a new char array, and finally creating a new string using that char array....
๐ŸŒ
Learn Java
javatutoring.com โ€บ reverse-a-string-in-java
Reverse A String In Java โ€“ 4 Ways | Programs
January 12, 2026 - 2) The 1st for loop iterates from i=0 to i< length of the array. a) If ch[i]!=โ€™ โ€˜ then adding ch[0] to the string word. If block adds the characters to the string word until we will get space i.e. word contains the 1st word. b) If we get space then the else block to reverse the word which is read using else block.