package com.instances;
/**
* @author Dell
* 将字符串反转的两种方法
*/
public class FanZhuan {
public static void main(String[] args) {
String s1="abcdefghi";
System.out.println("原字符串是:"+s1);
// String s2=reverse1(s1);
String s2=reverse2(s1);
System.out.println("翻转后字符串是:"+s2);
}
// 方法1
public static String reverse1(String s){
StringBuilder sb=new StringBuilder(s);
return sb.reverse().toString();
}
// 方法2
public static String reverse2(String s){
char[] c=new char[s.length()];
for (int x = 0; x < s.length(); x++) {
c[x]=s.charAt(s.length()-1-x);
}
return new String(c);
}
}