Created
August 4, 2014 21:49
-
-
Save rpomeroy/daea5f8a315dd9a941ca to your computer and use it in GitHub Desktop.
Java Reverse a String
This file contains hidden or 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
public static String reverse(String str) { | |
return new StringBuilder(str).reverse().toString(); | |
} | |
public static String reverseString(String str) { | |
char[] chars = str.toCharArray(); | |
String out = ""; | |
for(int i = chars.length - 1; i < 0; i--) { | |
out += chars[i]; | |
} | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment