public String reverse(String s) {
char[] reverseStringArray = new char[s.length()];
for (int i = s.length() – 1, j = 0; i != -1; i–, j++) {
reverseStringArray[j] = s.charAt(i);
}
return new String(reverseStringArray);
}

public String reverse(String s) {
if (s.length() <= 1) {
return s;
}
return reverse(s.substring(1, s.length())) + s.charAt(0);
}

Advertisements