Java Character codePointAt() 方法

2024年11月6日 | 阅读 6 分钟

此方法有 3 种语法。

Java Character codePointAt(char[] a, int index) 方法

Character 类的 codePointAt() 方法用于返回 char 数组中给定索引处的代码点。如果 char 数组中某个索引处的 char 值处于高代理范围,并且下一个索引小于 char 数组的索引,如果给定索引处的 char 值处于低代理范围,则返回该对对应的代码点。

语法

参数

上述方法需要两个参数

  • char 数组
  • 数组中 char 值的索引。

返回值

codePointAt() 方法返回数组中该索引处的字符值。

示例 1

输出

This is the first program for the given method :
32

示例 2

输出

Given String : javatpoint.com
Character Value = 97
Character Value = 105

示例 3

输出

The first string is = JAVA
Character(unicode point) = 65
The second string is = TPOINT
Character(unicode point) = 86

示例 4

输出

Java is a unique language.
Enter the desired index: 8
Result:  97

Java Character codePointAt(char[] a, int index, int limit) 方法

Character 类的 codePointAt(char[] a, int index, int limit) 方法返回 char 数组中给定索引处的代码点,其中只能使用索引小于 limit 的元素。如果 char 数组中某个索引处的 char 值处于高代理范围,并且下一个索引小于 limit。如果给定索引处的 char 值处于低代理范围,则返回该对对应的代码点。

语法

参数

上述方法需要三个参数

  • char 数组
  • 数组中 char 值的索引。
  • limit 是数组中最后一个可用元素的下一个索引。

返回值

此方法返回给定索引处的 Unicode 代码点。

示例 5

输出

Hello
Unicode code point is : 108
Everyone
Unicode code point is : 108

示例 6

输出

The numbers are:  '1', '2', '3', '4', '5' 
Unicode code point is 50

示例 7

输出

Hello
Unicode code point for Hello is 108
The numbers are:  '1', '2', '3', '4', '5' 
Unicode code point for number is 108

Java Character codePointAt(CharSequence seq, int index) 方法

Character 类的 codePointAt(CharSequence seq, int index) 方法返回 charSequence 中特定索引处的代码点。如果 charSequence 中某个索引处的 char 值处于高代理范围,则下一个索引将小于 charSequence 的长度。另一方面,如果 charSequence 中的 char 值处于低代理范围,则返回给定代理对对应的补充代码点。

语法

参数

上述方法需要两个参数

  • char 值序列。
  • 要转换为 seq 的 char 值的索引。

返回值

此方法返回特定索引处的 Unicode 代码点。

示例 8

输出

Java is secured
The Unicode code point is 97

示例 9

输出

Java is secured
The Unicode code point for Java is 118
The numbers are:  '1', '2', '3', '4', '5' 
The Unicode code point for number is 52

示例 10

输出

Java is more portable
The Unicode code point for Java is 118
Java is based on the concepts of OOPS.
The Unicode code point for Java is 118