/**
*
* @description
* <p>String utils</p>
* @author Czp
* @version 1.0(2014-5-9)
*
*/
public class StringUtil {/**
* @description:
* <p>反转字符串,如果参数为null或为空窜将返回原对象</p>
* @param str
* @return
*/
public static String reverseString(String str) {
if (str == null || str.isEmpty())
return str;
char[] arr = str.toCharArray();
int len = arr.length - 1;
for (int i = 0; i < len; i++, len--) {
char tmp = arr[i];
arr[i] = arr[len];
arr[len] = tmp;
}
return new String(arr);
}
}
算法-倒置字符串
时间: 2024-10-06 11:36:43