Java SE API

String.offsetByCodePoints

Move from a UTF-16 index by given code points; invalid index or insufficient code points throws IndexOutOfBoundsException.

Formal Syntax & Structure

java syntaxjava
public int offsetByCodePoints(int index, int codePointOffset)

Parameters & Attributes

NameTypeDescription
indexintStarting index.
codePointOffsetintSigned offset.

Return Value

int

Resulting UTF-16 index.

Working Example

Example Snippetjava
import java.util.Locale;public class Main {    public static void main(String[] args) {        String text = "\uD83D\uDE80A";        int end = text.offsetByCodePoints(0, 1);        String first = text.substring(0, end);        System.out.println(first.codePointAt(0));        System.out.println(first.length());        System.out.println("ITEM".toLowerCase(Locale.ROOT));    }}
Java Reference