Created
September 1, 2020 19:28
-
-
Save mstoic/b2a7cd926aecfe8bab313075883973c3 to your computer and use it in GitHub Desktop.
Reverse a String Using StringBuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StringBuilder str = new StringBuilder("Hey"); | |
int len = str.length(); | |
for (int i = 0; i < len; i++) { | |
str.append(str.substring(len - 1 - i, len - i)); | |
} | |
str.delete(0, len); | |
System.out.println("string: " + str); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment