Skip to content

Instantly share code, notes, and snippets.

@mstoic
Created September 1, 2020 19:28
Show Gist options
  • Save mstoic/b2a7cd926aecfe8bab313075883973c3 to your computer and use it in GitHub Desktop.
Save mstoic/b2a7cd926aecfe8bab313075883973c3 to your computer and use it in GitHub Desktop.
Reverse a String Using StringBuilder
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