Reverse a string.
public String reverseIterative(String str) {
StringBuilder strBuilder = new StringBuilder();
char[] strChars = str.toCharArray();
for (int i = strChars.length-1; i >= 0; i--) {
strBuilder.append(strChars[i]);
}
return strBuilder.toString();
}
public String reverseRecursive(String str) {
if (str.length() == 1) {
return str;
}
return reverseRecursive(str.substring(1)) + str.charAt(0);
}