58,454
社区成员
发帖
与我相关
我的任务
分享
/**
* @author Andy
*
*/
public class ReverseString {
public ReverseString() {
}
public static String reverse(String source) {
if (source.equals(""))
return null;
char[] array = source.toCharArray();
StringBuffer strBuf = new StringBuffer(array.length);
for (int i = array.length-1; i >= 0; i--) {
char ch = array[i];
strBuf.append(ch);
}
return strBuf.toString();
}
public static void main(String[] args) {
String before="I love Java";
String after = reverse(before);
System.out.println(after);
}
}