Java Character offsetByCodePoints() Method

The offsetByCodePoints(char[]a, int start, int count, int index, int codePointOffset) method of Character class returns the specified index within the given char sub-array which has been offset by codePointOffset codePoints. The start and count parameter specifies a sub-array of the char array. All the unpaired surrogates which lie in the text range given by the index and the codePointOffset are counted as one codePoint each.

Syntax

Parameter

The above method requires five parameters:

  • The char type array.
  • The start which is the index of the first character of the given sub-array.
  • The count is the total length of the sub-array.
  • The index that needs to be offset.
  • The codePointOffset is the offset in the codepoints.

Return Value

The offsetByCodePoints(char[]a, int start, int count, int index, int codePointOffset) method returns the specified index within the subarray.

Example 1

Output:

The index within the subarray ch is given as: 6

Java Character offsetByCodePoints(CharSequence seq, int index, int codePointOffset) Method

The offsetByCodePoints(CharSequence seq, int index, int codePointOffset) method of Character class returns the specified index within the given character sequence which has been offset from the given index by the codePointOffset codePoints.

All the unpaired surrogates which lie in the text range given by the index and the codePointOffset are counted as one codePoint each.

Syntax

Parameter

The above method requires three parameters:

  • The character sequence seq.
  • The index that needs to be offset.
  • The codePoint offset.

Return Value

The offsetByCodePoints(CharSequence seq, int index, int codePointOffset) method returns the specified index in the character sequence.

Example 1

Output:

The result for the above method can be represented as:24