JavaHow To Reverse a String
Reverse a String
You can easily reverse a string by characters with the following example:
Example
String originalStr = "Hello";String reversedStr = "";for (int i = 0; i < originalStr.length(); i++) { reversedStr = originalStr.charAt(i) + reversedStr;}System.out.println("Reversed string: "+ reversedStr);Try it Yourself »Explanation: We start with an empty stringreversedStr.
- On each loop, we take one character from the original string usingcharAt().
- Instead of adding it to the end, we place it in front of the existingreversedStr.
- This way, the characters are built in reverse order.
For example, from"Hello" we get"olleH".

