Java Character offsetByCodePoints()方法

java.lang.Character.offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset) 返回给定的字符子阵列是给定的索引由codePointOffset代码点偏移中的索引。

start和count参数指定的字符数组的子数组。通过索引和codePointOffset给定的文本范围内未配对的代理算作每一个代码点。

1 语法

public static int offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset)

2 参数

a:字符数组

start:子数组的第一个字符的索引

count:字符子数组的长度

index:索引被抵消

codePointOffset:偏移的代码点

3 返回值

此方法返回的子数组中的索引。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java Character offsetByCodePoints()方法
 */
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', 'f' };

      // craete 2 int primitives start, count and assign values
      int start = 1;
      int count = 5;

      // create an int primitive res
      int res;

      // assign result of offsetByCodePoints on subarray of c to res
      res = Character.offsetByCodePoints(c, start, count, 2, 4);

      String str = "The index within the subarray of c is " + res;

      // print res value
      System.out.println( str );
   }
}

输出结果为:

The index within the subarray of c is 6

 

热门文章

优秀文章