Java Character codePointCount() 方法

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

此方法有 2 种语法。

Java Character codePointCount(char[]a, int offset, int count) 方法

codePointCount(char[]a, int offset, int count) 方法用于返回 char 数组子数组中的 Unicode 代码点的数量。offset 参数是给定 char 数组中第一个 char 的索引,count 参数指示子数组的长度。

语法

参数

上述方法需要三个参数

  • char 数组。
  • offset 是给定 char 数组中第一个 char 的索引。
  • count 是给定 char 中子数组的长度。

返回值

此方法返回指定子数组中的 Unicode 代码点的数量。

示例 1

输出

Welcome to our tutorial site:
The result is given as: 2

示例 2

输出

The alphabets are: 'a', 'b', 'c', 'd', 'e'
The number of Unicode code point for alphabets are 4
The numbers are:  '1', '2', '3', '4', '5'
The number of Unicode code point for numbers are 3

示例 3

输出

Hello everyone
6 is generated because method counts the first argument.
Everyday is a fun day
2 is generated because method counts the second argument.

Java Character codePointCount() 方法

Character 类的 codePointCount(CharSequence seq, int beginIndex, int endIndex) 方法用于返回特定 char 序列的文本范围内的 Unicode 代码点的数量。文本范围从 beginIndex 开始,到 endIndex 结束。

语法

参数

上述方法需要三个参数

  • char 序列。
  • beginIndex 是文本范围第一个 char 的索引。
  • endIndex 是文本范围最后一个 char 之后的索引。

返回值

codePointCount(CharSequence seq, int beginIndex, int endIndex) 方法返回指定文本范围内的 Unicode 代码点的数量。

示例 4

输出

This is a unique example!
The result comes to be:25

示例 5

输出

This is a unique example!
The result comes to be:25
Hello World!
Number of Unicode code points is 4

示例 6

输出

This is a unique example!
The result comes to be: 25
Java is a high level language!
The result comes to be: 30
Java is based on the cocepts of OOPS!
The result comes to be: 37