Java.lang.Character.codePointAt() 方法
描述
java.lang.Character.codePointAt(char[ ] a, int index) 返回 char 数组给定索引处的代码点。
如果char数组中给定索引处的char值在高代理范围内,则后面的索引小于char数组的长度,后面索引处的char值在低代理范围内 范围,则返回与该代理对对应的补充代码点。 否则,返回给定索引处的 char 值。
声明
以下是 java.lang.Character.codePointAt() 方法的声明。
public static int codePointAt(char[] a, int index)
参数
a − 字符数组
index − 要转换的 char 数组中的 char 值(Unicode 代码单元)的索引
返回值
此方法返回给定索引处的 Unicode 代码点。
异常
NullPointerException − 如果 a 为空。
IndexOutOfBoundsException − 如果值索引为负数或不小于 char 数组的长度。
示例
下面的例子展示了 lang.Character.codePointAt() 方法的使用。
package com.tutorialspoint;
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' };
// craete 2 int's res, index and assign value to index
int res, index = 0;
// assign result of codePointAt on array c at index to res
res = Character.codePointAt(c, index);
String str = "Unicode code point is " + res;
// print res value
System.out.println( str );
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Unicode code point is 97

