Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Java String offsetByCodePoints() Method?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___ myStr = "Hello, World!";3Order
Put the learning moves in the order that makes the concept easiest to apply.
The offsetByCodePoints() method returns an index in a string which is offset from another index by a specified number of code points.
Definition and Usage
Java String offsetByCodePoints() Method
❮ String Methods
Example
String myStr = "Hello, World!";
int result = myStr.offsetByCodePoints(3, 2);
System.out.println(result);Definition and Usage
The offsetByCodePoints() method returns an index in a string which is offset from another index by a specified number of code points.
Note
A code point may be formed by more than one character. These code points will offset the index by more than 1.
Syntax
public int offsetByCodePoints(int
index , int
codePointOffset )Parameter Values
| Parameter | Description |
|---|---|
| index | Required. Specifies the index in the string to measure the offset from. |
| codePointOffset | Required. Specifies the number of code points to offset by. Positive values will return a number greater than index and negative values will return a number less than index . |
Technical Details
| Returns: | An int representing the index which is codePointOffset code points away from index . |
|---|---|
| Throws: | IndexOutOfBoundsException - If index is negative or greater than the length of the string or if there are not enough code points in the string to offset by codePointOffset . |
| Java version: | 1.5 |