标签:字符串反转
参考1:http://blog.csdn.net/clbxp/article/details/6625142
类别 |
字符个数 |
字节个数 |
bit位 |
字符 |
1 |
2 |
16 |
普通汉字 |
1 |
2 |
16 |
超大字符集(生僻汉字等) |
2 |
4 |
32 |
public AbstractStringBuilder reverse() { boolean hasSurrogate = false; int n = count - 1; for (int j = (n-1) >> 1; j >= 0; --j) { char temp = value[j]; char temp2 = value[n - j]; if (!hasSurrogate) { hasSurrogate = (temp >= Character.MIN_SURROGATE && temp <= Character.MAX_SURROGATE) || (temp2 >= Character.MIN_SURROGATE && temp2 <= Character.MAX_SURROGATE); } value[j] = temp2; value[n - j] = temp; } if (hasSurrogate) { // Reverse back all valid surrogate pairs for (int i = 0; i < count - 1; i++) { char c2 = value[i]; if (Character.isLowSurrogate(c2)) { char c1 = value[i + 1]; if (Character.isHighSurrogate(c1)) { value[i++] = c1; value[i] = c2; } } } } return this; }*******************************************************************************************************************
/** * 创建时间:2014年8月15日 下午9:44:51 * 项目名称:Test * @author Cao Yanfeng * @since JDK 1.6.0_21 * 类说明: */ public class AccuracyTest { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String string="caoyanfeng曹艳丰北京大学标签:字符串反转
原文地址:http://blog.csdn.net/brillianteagle/article/details/38637603