// 字符串的倒序排列。
public static void main(String[] args){
String s="I LOVE YOU";
// 方法1: toCharArray()的用法
char[] c=s.toCharArray();
for(int i=c.length-1;i>=0;i--){
System.out.print(c[i]);
}
System.out.println();
// 方法2:stringBuilder.reverse();
StringBuilder stringBuilder=new StringBuilder(s);
StringBuilder sb=stringBuilder.reverse();
System.out.println(sb);
// 方法3:stringBuffer.reverse();
StringBuffer stringBuffer=new StringBuffer(s);
StringBuffer sf=stringBuffer.reverse();
System.out.println(sf);
// 方法4:递归的方法
reverseString (s);
}
public static void reverseString (String str){
if (str.length() == 1){
System.out.print(str);
}
else
{
String subString1 = str.substring(0, str.length()-1);
String subString2 = str.substring(str.length()-1);
System.out.print(subString2);
reverseString (subString1);
}
}