- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java.lang.Character.offsetByCodePoints() Method
Description
The java.lang.Character.offsetByCodePoints(CharSequence seq, int index, int codePointOffset) 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.
Declaration
Following is the declaration for java.lang.Character.offsetByCodePoints() method
public static int offsetByCodePoints(CharSequence seq, int index, int codePointOffset)
Parameters
- seq − the char sequence
- index − the index to be offset
- codePointOffset − the offset in code points
Return Value
This method returns the index within the char sequence
Exception
NullPointerException − if seq is null
IndexOutOfBoundsException − if index is negative or larger then the length of the char sequence, or if codePointOffset is positive and the subsequence starting with index has fewer than codePointOffset code points, or if codePointOffset is negative and the subsequence before index has fewer than the absolute value of codePointOffset code points.
Example
The following example shows the usage of lang.Character.offsetByCodePoints() method.
package com.tutorialspoint; import java.lang.*; public class CharacterDemo { public static void main(String[] args) { // create a CharSequence seq and assign value CharSequence seq = "Hello World"; // create an int primitive res int res; // assign result of offsetByCodePoints on seq to res res = Character.offsetByCodePoints(seq, 3, 8); String str = "The index within the char sequence seq is " + res; // print res value System.out.println( str ); } }
Let us compile and run the above program, this will produce the following result −
The index within the char sequence seq is 11