You can make use of StringBuilder#reverse() method like this:

String reverse = new StringBuilder(new String(letters)).reverse().toString();
Answer from anubhava on Stack Overflow
Top answer
1 of 4
4

In terms of time complexity, they're both O(n). Performance wouldn't be significant here.

Which to choose? None. I would use a ready method StringBuilder#reverse:

String reversed = new StringBuilder(new String(c)).reverse().toString();

If I wanted to choose one from the two methods you posed, I would have choose the first one, it have only one loop and it's straightforward, no methods will be called, no helper objects will be created; you simply create a new array and directly push to it the new elements.

2 of 4
3

@MarounMaroun's answer will work for char arrays that are really strings. If you are worried only about those two methods then the first involves less heap allocations and GC.

However in general for an array I would use neither of your methods, but instead:

int len = c.length; 
for(int i = 0; i < len / 2; i++) {
    char ch = c[i];
    c[i] = c[len - i - 1];
    c[len - i - 1] = ch;
}

It is:

  1. shorter to type than method 2
  2. only iterates for half the array length (it is still O(n) due to the ops per iteration)
  3. will work for any array type
  4. doesn't need extra object allocations (vs Method 2) or two arrays (vs Method 1)

I would, however, be careful of micro-optimizations like this. The difference between this and Method 1 is probably minimal for small array allocations so you are better off using the one that is easiest for you to understand. (Similarly I only pulled the len variable out for clarity - some microbenchmarks claim it speeds up loops, but the downside is it pollutes your local variables with something that is only used inside the loop).

🌐
GeeksforGeeks
geeksforgeeks.org › java › reverse-a-string-in-java
Reverse a String in Java - GeeksforGeeks
We can use character array to reverse a string. Follow Steps mentioned below: First, convert String to character array by using the built-in Java String class method toCharArray().
Published   October 14, 2025
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 419799 › trying-to-do-char-array-reverse
java - Trying to do Char array reverse? [SOLVED] | DaniWeb
char[] letters = {'A','B','C',... } If you actually need the array reversed (not just printed in reverse), do it in-place with a two-pointer swap....
🌐
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 - Here we have used a character array as an example. Using the reverse function, we reverse the array elements one by one and then display the reversed array.
🌐
coderolls
coderolls.com › reverse-a-string-in-java
How To Reverse A String In Java (5 ways) - Coderolls
December 2, 2019 - Create a new char array using the blogName string. eg. stringCharArray · Create an empty string, we will be using that string to append with elements of the stringCharArray. Let say the empty string is reversedString. Apply for loop to iterate stringCharArray in the reverse order. In the for loop, append the reversedString with the ith element of the stringCharArray. Print the reversedString. I have given the program as per the above logic. /** * A Java program to reverse a string.
🌐
LeetCode
leetcode.com › problems › reverse-string › solutions › 1668059 › java-solution-for-reversing-char-array
java solution for reversing char Array
Can you solve this real interview question? Reverse String - Write a function that reverses a string. 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.
Find elsewhere
🌐
YouTube
youtube.com › vikki r
🔴Frequently Asked Java Program 02: How to reverse a string using char array in JAVA? - YouTube
#reversestring #frequentlyaskedjavaprogram #javaIn this video, you will learn how to Reverse A String using Char array in JAVA#Automation #maven #dependencie...
Published   February 14, 2022
Views   896
🌐
YouTube
youtube.com › anwar mamat
Reverse each word in character array - YouTube
Reverse each word in a character array using java
Published   June 10, 2018
Views   3K
🌐
Squash
squash.io › how-to-reverse-a-string-in-java
How to Reverse a String in Java
Another approach to reverse a string in Java is by converting the string to a char array and then swapping the characters from both ends of the array.
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › String › toCharArray
Java String toCharArray() - Convert To Char Array | Vultr Docs
January 1, 2025 - This code takes the string original, converts it to an array, reverses the array, and constructs a new string from the reversed array. The toCharArray() method is a versatile and powerful tool in Java for string manipulation and analysis. Whether ...
🌐
Medium
medium.com › @jasonwei_613 › java-reverse-string-recursion-f3dcaa3d90e2
Java Reverse String (Recursion). How do you use Recursion to reverse an… | by Jason Wei | Medium
May 21, 2019 - The question specifically state not to return the array, but to modify it. ... class Solution { public void reverseString(char[] s) { helper(0,s); } private void helper(int index, char[]s){ if(index >= s.length-index-1 || s== null){ return; } char temp = s[index]; s[index]=s[s.length-index-1]; s[s.length-index-1] = temp; helper(1+ index, s); } } }
🌐
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.
🌐
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
🌐
JavaBeat
javabeat.net › home › how to reverse a string in java?
How to Reverse a String in Java?
January 31, 2024 - The CharArray is then printed using the reverse iteration. By using the following line of code, import the necessary dependencies and classes from the “java.util” package: ... The string variable “str” is initialized with the following values. The character array “reverseString” stores the string in the form of characters which is returned by the toCharArray().
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › reverse-a-string-in-java
Reverse a String in Java? - A Complete Guide
public static String reverseStringUsingXOR(String str) { char[] chars = str.toCharArray(); char[] reversedChars = new char[chars.length]; // Reverse the original string for (int i = 0; i < chars.length; i++) { reversedChars[i] = chars[chars.length ...
🌐
Dot Net Perls
dotnetperls.com › reverse-string-java
Java - String Reverse - Dot Net Perls
And We assign the array elements to a string character indexed from the opposite (inverted) side. This reverses the characters.
🌐
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 - Now let us understand this with the help of an example: public class Main { // In this Method of conversion we have to reverse a string in Java using a character array public static String reverse(String s1) { // we have to check if the string is empty or not and return if the string is null ...