Retrieve an index within a string that is shifted from another index by a specified number of code points.
String |
The offsetByCodePoints() method provides an index within a string that is shifted from another index by a specified number of code points.
Note: A code point might consist of multiple characters, resulting in an offset of more than 1 for the index.
public |
Parameter |
Description |
Index |
Necessary. Specifies the index in the string from which the offset is measured. |
Codepoint offset |
Mandatory. Indicates the number of code points by which to offset. Positive values will result in a number greater than the index, while negative values will yield a number less than the index. |
Returns: |
An integer representing the index that is offset by a number of code points from the given index. |
Throws: |
An IndexOutOfBoundsException will be thrown if the index is negative or exceeds the length of the string, or if there are insufficient code points in the string to offset by the specified codePointOffset. |
Java Version |
1.5 |