I am trying to create a method that reverses a string that will handle every case. So far the cases I have come up with are
""
"abcdef"
"abbbba"
null
I haven't been able to handle these conditions however
escape characters
"\n"
"\t"
Not sure how to make \n
or \t
into a string
special characters such as
áe
code:
public static String reverseStr(String str) {
if ( str == null ) {
return null;
}
int len = str.length();
if (len <= 0) {
return "";
}
char[] strArr = new char[len];
int count = 0;
for (int i = len - 1; i >= 0; i--) {
strArr[count] = str.charAt(i);
count++;
}
return new String(strArr);
}