Last Updated : 19 Jul, 2022
The Character.offsetByCodePoints(CharSequence seq, int index, int codePointOffset) is an inbuilt method in java that returns the index within the given char sequence that is offset from the given index by codePointOffset code points. Unpaired surrogates within the text range given by index and codePointOffset count as one code point each.
Syntax:
public static int offsetByCodePoints(CharSequence seq, int index, int codePointOffset)
Parameters:
Return value: This method of Character class returns the index within the char sequence.
Exceptions:
Below are the programs to illustrate the above mentioned method:
Program 1:
Java
// Code to illustrate the offsetByCodePoints() method
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// Create a CharSequence s and assign value
CharSequence s = "Hello World";
// Result of offsetByCodePoints on s
String str = "The index within the char sequence s is " +
Character.offsetByCodePoints(s, 2, 6);
// Print str value
System.out.println(str);
}
}
Output:
The index within the char sequence s is 8
Program 2:
Java
// Code to illustrate the offsetByCodePoints() method
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// Create a CharSequence s and assign value
CharSequence s = "geeks for geeks";
// Result of offsetByCodePoints on s
String str = "The index within the char sequence s is " +
Character.offsetByCodePoints(s, 3, 8);
// Print str value
System.out.println(str);
}
}
Output:
The index within the char sequence s is 11
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4