Java中4字节的字符处理案例

String str = "abc我们";

 

int charNums = str.codePointCount(0, str.length());

System.out.println(charNums);//6

for(int i=0;i

    char[] chars = Character.toChars(str.codePointAt(i));

    System.out.print(new String(chars)+";");

}//a;b;c;我;们;;

System.out.println();

 

System.out.println(str.length());//7

for(int i=0;i

    System.out.print(str.charAt(i)+";");

}//a;b;c;我;们;?;?;

你可能感兴趣的:(问题集锦,计算机基础)