🌐
GeeksforGeeks
geeksforgeeks.org › dsa › reverse-a-string
Reverse a String – Complete Tutorial - GeeksforGeeks
// C program to reverse a string using two pointers #include <stdio.h> #include <string.h> char* reverseString(char *s) { int left = 0, right = strlen(s) - 1; // Swap characters from both ends till we reach // the middle of the string while (left < right) { char temp = s[left]; s[left] = s[right]; s[right] = temp; left++; right--; } return s; } int main() { char s[] = "abdcfe"; printf("%s", reverseString(s)); return 0; } ... // Java program to reverse a string using two pointers class GfG { static String reverseString(String s) { int left = 0, right = s.length() - 1; // Use StringBuilder for m
Published   October 3, 2025
🌐
Java67
java67.com › 2016 › 06 › how-to-reverse-string-in-place-in-java.html
[Solved] How to reverse a String in place in Java? Example | Java67
It will also make you a better programmer because you know how to solve an unseen problem using existing patterns. That's all about how to reverse String in place in Java. This is a common algorithm that uses two pointer approach. Since it requires us to traverse the array till the middle, the time complexity is O(n/2) i.e.
People also ask

What is a String in Java?
Strings in Java are immutable (cannot be changed) non-primitive datatype that stores a sequence or array of characters.
🌐
shiksha.com
shiksha.com › home › it & software › it & software articles › programming articles › reverse a string in java
Reverse a String in Java - Shiksha Online
What are Lists in Java?
Java has ArrayLists which are arrays that resize themselves as needed. A typical implementation is when the array is full, the array doubles in size.
🌐
shiksha.com
shiksha.com › home › it & software › it & software articles › programming articles › reverse a string in java
Reverse a String in Java - Shiksha Online
🌐
Medium
medium.com › @YodgorbekKomilo › two-pointer-technique-in-java-58542f961ac8
Two-Pointer Technique in Java. The two-pointer technique in Java… | by Yodgorbek Komilov | Medium
September 30, 2024 - public class ReverseString { public static String reverse(String s) { char[] chars = s.toCharArray(); int left = 0, right = chars.length - 1; while (left < right) { char temp = chars[left]; chars[left] = chars[right]; chars[right] = temp; left++; right--; } return new String(chars); } public static void main(String[] args) { String s = "Hello, World!"; String reversed = reverse(s); System.out.println(reversed); // Output: !dlroW ,olleH } } This example merges two sorted arrays into one sorted array. import java.util.Arrays; public class MergeSortedArrays { public static int[] merge(int[] arr1,
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › reverse-a-string-in-java
Reverse a String in Java? - A Complete Guide
Two pointers, 'left' and 'right', are initialized to point to the first and last characters of the Java Array, respectively. In the while loop, the characters pointed to by 'left' and 'right' are interchanged using a temporary variable, 'temp', and the pointers are moved towards each other until they meet at the middle of the array. To reverse a string using the creation of a new string, firstly, you must create an empty string to store the reversed string.
🌐
Interviewing.io
interviewing.io › questions › reverse-string
How to Reverse a String [Interview Question + Solution]
September 13, 2018 - Convert the string to a character array char_array. Initialize two pointers, start and end, to point at the start and the end of the string, respectively. Loop until start is less than end.
🌐
LeetCode
leetcode.com › problems › reverse-words-in-a-string-iii › discuss › 236915 › java-2-pointers-without-built-in-reverse-and-split-methods
Loading...
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
🌐
Emeritus
emeritus.org › home › blog › information technology › 9 most convenient ways to reverse a string in java
9 Most Convenient Ways to Reverse a String in Java
September 24, 2024 - In the above example, the ‘toCharArray()’ method converts the input string into a character array. Then two pointers named ‘left’ and ‘right’ point to the first and last character of the array respectively. Next, the ‘left’ and ‘right’ pointer exchanges their pointed characters using a temporary variable ‘temp’ in the while loop. Lastly, the code prints the original and reversed string using the ‘System.out.printIn()’ method.
🌐
Shiksha
shiksha.com › home › it & software › it & software articles › programming articles › reverse a string in java
Reverse a String in Java - Shiksha Online
September 18, 2023 - Then, we’ll put 2 pointers at the first and last element. Afterwards, we’ll swap the first and last characters using the XOR (^) operation, the second and second the last element, and so on.
Find elsewhere
🌐
Medium
josephinegyamera.medium.com › exploring-recursion-and-pointers-through-reversestring-c0581fda66c4
Exploring Recursion and Two-Pointers Through ReverseString | by Josephine Gyamera | Medium
February 23, 2024 - In this method, we employ Two-pointers, one starting from the beginning of the string (left) and the other from the end (right). We swap characters until the pointers meet at the center, effectively reversing the string.
🌐
InterviewBit
interviewbit.com › coding problems › reverse string (c++, java, and python)
Reverse String (C++, Java, and Python) - InterviewBit
June 23, 2023 - def reverseString(self, s): def helper(left, right): if left < right: s[left], s[right] = s[right], s[left] helper(left + 1, right - 1) helper(0, len(s) - 1) Time Complexity:O(N), where N is the length of the string. Space Complexity:O(N), since the recursion stack takes space. Another simple approach to solve this problem is to use two pointers method.
🌐
Baeldung
baeldung.com › home › algorithms › java two pointer technique
Java Two Pointer Technique | Baeldung
April 4, 2025 - Let’s solve this using the two-pointer technique instead: public void rotate(int[] input, int step) { step %= input.length; reverse(input, 0, input.length - 1); reverse(input, 0, step - 1); reverse(input, step, input.length - 1); } private ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › reverse-a-string-in-java
Reverse a String in Java - GeeksforGeeks
Explanation: Characters are stored in a list and reversed using Collections.reverse(). This approach is helpful when you’re already working with Java collections. StringBuffer is similar to StringBuilder but thread-safe.
Published   October 14, 2025
🌐
YouTube
youtube.com › watch
Reverse String - Leetcode 344 - 2 Pointers - (Python) - YouTube
Master Data Structures & Algorithms for FREE at https://AlgoMap.io/Code solutions in Python, Java, C++ and JS for this can be found at my GitHub repo here: h...
Published   April 17, 2024
🌐
Medium
javafullstackdev.medium.com › how-to-reverse-a-string-in-java-a-comprehensive-guide-b2720a975891
How to Reverse a String in Java: A Comprehensive Guide | by fullstackjavadev.in | Medium
June 7, 2024 - Swap the characters at these two pointers. Move the pointers towards the center. Repeat the process until the pointers meet in the middle. Convert the reversed character array back to a string and print it.
🌐
coding algorithms
tekmarathon.com › 2012 › 10 › 05 › algorithm-to-reverse-a-string
algorithm to reverse a string array in O(n/2) complexity | coding algorithms
November 18, 2015 - String str = “welcome to javaj2ee forum”; //take two pointers, one pointing to the start of String and another to the end of the string // while traversing the String increment starting pointer and decrement ending pointer and continue this ...
🌐
AlgoMonster
algo.monster › liteproblems › 344
344. Reverse String - In-Depth Explanation
In-depth solution and explanation for LeetCode 344. Reverse String in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.
🌐
Medium
medium.com › @tharindanimsara457 › what-is-java-string-reverse-b81877bb8612
What is Java String Reverse ???. In Java, there are multiple ways to… | by CodeCascade | Medium
June 15, 2024 - The reverseString method takes a string str as input. We convert str to a character array charArray using str.toCharArray(). We use a two-pointer approach with left and right indices.
🌐
AlgoMonster
algo.monster › liteproblems › 541
541. Reverse String II - In-Depth Explanation
In-depth solution and explanation for LeetCode 541. Reverse String II in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.