Java String codePointAt() 方法

实例

返回字符串中第一个字符的 Unicode(Unicode 值 "H" 为 72):

  1. public class Main {
  2. public static void main(String[] args) {
  3. String myStr = "Hello";
  4. int result = myStr.codePointAt(0);
  5. System.out.println(result);
  6. }
  7. }

定义与用法

codePointAt() 方法返回字符串中指定索引处字符的 Unicode 值。

第一个字符的索引为 0,第二个字符的索引为 1,依此类推。


语法


参数值

参数描述
index一个 int 值,表示要返回的字符的索引

技术细节

返回:一个 int 值,表示索引处字符的 Unicode 值
异常:IndexOutOfBoundsException - 如果索引为负或不小于指定字符串的长度
Java 版本:1.5

分类导航