- public String reverse(String str) {
- char[] chars = str.toCharArray();
- for (int i = 0; i < chars.length / 2; i++) {
- //第一个和最后一个交换,第二个和倒数第二个交换 .......
- char tmp=chars[i];
- chars[i]=chars[chars.length-1-i];
- chars[chars.length-1-i]=tmp;
- }
- return new String(chars);
- }
复制代码
|