//1. 使用数组循环
public static string array(string s){
int length=s.length();
char[] array=s.tochararray();
for(int i=0;i=0;i--){
sb.append(s.charat(i));
}
return sb.tostring();
} //stringbuilder比stringbuffer快,但线程不安全
//4.栈的后进先出
public static string reversebystack(string str) {
if(str == null || str.length() == 0) {
return str;
}
stack strstack = new stack();
char[] charray = str.tochararray();
for(character ch: charray) {
strstack.push(ch);
}
int len = str.length();
for(int i= 0; i< len; i ) {
charray[i] = strstack.pop();
}
return new string(charray);
}
5. 迭代完成
public static string reversebyrecursive(string str) {
if(str == null || str.length() == 0) {
return str; }
int len = str.length();
if(len == 1) {
return str;
} else {
return reversebyrecursive(str.substring(1)) str.charat(0);
}
}