Java.lang.String 类

java.lang.String.codePointAt() 方法返回给定字符串中指定索引处的字符(Unicode 代码点)。 索引参数必须在 0 到 length() - 1 的范围内。

语法

public int codePointAt(int index) 

参数

index指定 char 值的索引。

返回值

返回索引处字符的代码点值。

Exception

如果索引参数为负数或不小于字符串的长度,则抛出 IndexOutOfBoundsException .

示例:

在下面的示例中,codePointAt() 方法返回指定索引 在名为 MyString 的字符串中。

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    String MyString = "Hello World!";
    System.out.println(MyString.codePointAt(1));   
  }
} 

上述代码的输出将是:

101