java.lang.Character.codePointCount(char[ ] a, int offset, int count)%uA0返回char数组参数的一个子Unicode代码点的数量。
offset参数是子数组和count参数的第一个字符的索引指定于字符子数组的长度。子数组内未配对的代理算作每一个代码点。
声明
以下是java.lang.Character.codePointCount()方法的声明
public static int codePointCount(char[] a, int offset, int count)
参数
-
a%uA0- char数组
-
offset%uA0- 第一个字符的给定char数组中的索引
-
count%uA0- %uA0字符子数组的长度
返回值
此方法将返回指定子数组Unicode代码点的数量。
异常
-
NullPointerException%uA0- 如果a为null。
-
IndexOutOfBoundsException%uA0- 如果offset或count为负,或者如果 offset + count大于给定数组的长度。
例子
下面的例子显示lang.Character.codePointCount()方法的使用。
package com.yiibai import java.lang.* public class CharacterDemo { public static void main(String[] args) { // create a char array c and assign values char[] c = new char[] { &aposa&apos, &aposb&apos, &aposc&apos, &aposd&apos, &apose&apos } // create and assign value to offset, count int offset = 1, count = 3 // create an int res int res // assign result of codePointCount on subarray of c to res res = Character.codePointCount(c, offset, count) String str = "No. of Unicode code points is " + res // print res value System.out.println( str ) } }
让我们来编译和运行上面的程序,这将产生以下结果:
No. of Unicode code points is 3