JAVA实现字符串反转,借助字符数组实现

时间:2023-03-08 21:37:02
public static String reverseStr(String str) {
int len = str.length();
char ch[] = str.toCharArray();
int begin = 0,end = len-1;
char temp;
while(begin<end) {
temp = ch[begin];
ch[begin] = ch[end];
ch[end] = temp;
begin++;
end--;
}
return new String(ch);
}

以上程序就是JAVA实现字符串反转的简单程序,非常简单,使用方便!!

新浪微博:http://weibo.com/cwtree

优酷空间:http://i.youku.com/u/UMzEzODI0NTQ4