java.lang.Character.codePointCount(char[ ] a, int offset, int count) 返回char陣列引數的一個子Unicode程式碼點的數量。
offset引數是子陣列和count引數的第一個字元的索引指定於字元子陣列的長度。子陣列內未配對的代理算作每一個程式碼點。
以下是java.lang.Character.codePointCount()方法的宣告
public static int codePointCount(char[] a, int offset, int count)
a - char陣列
offset - 第一個字元的給定char陣列中的索引
count - 字元子陣列的長度
此方法將返回指定子陣列Unicode程式碼點的數量。
NullPointerException - 如果a為null。
IndexOutOfBoundsException - 如果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[] { 'a', 'b', 'c', 'd', 'e' }; // 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