23,407
社区成员
发帖
与我相关
我的任务
分享
int[] codePoints = new int[16];
for (int i = 0; i < 16; i++)
{
codePoints[i] = 0x20020 + i;
}
String a = new String(codePoints, 0, codePoints.length);
System.out.println("字符串:" + a);
System.out.println("字符串换算成 char[] 存储总长度是 :" + a.length());
System.out.println("codePointAt(7) 索引换算成 charAt 索引 :" + a.offsetByCodePoints(1, 7));
String c = a.substring(a.offsetByCodePoints(1, 7), a.offsetByCodePoints(1, 8));
System.out.println("UTF-8 for " + c + " is " + toString(c.getBytes("UTF-8")) + " ==> "
+ new String(c.getBytes("UTF-8"), "UTF-8"));