Character.offsetByCodePoints() in Java with Examples Last Updated : 12 May, 2022 Comments Improve Suggest changes Like Article Like Report The Character.offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset) is an inbuilt method in Java that returns the index within the given char subarray that is offset from the given index by codePointOffset code points. The start and count arguments specify a subarray of the char array. Unpaired surrogates within the text range given by index and codePointOffset count as one code point each. The offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset) method of Character class is static thus it should be accessed statically. A non-static method is usually called by declaring method_name(argument). But in this case, since it is a static method, the class name is appended as a suffix, during the call. A compilation problem may be encountered if the java offsetByCodePoints() method is tried to be called in a non-static manner. Syntax: public static int offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset) Parameters: a: the char arraystart: the index of the first char of the subarraycount: the length of the subarray in charsindex: the index to be offsetcodePointOffset: the offset in code points Return value: This method returns an integer type value i.e., the index, within the subarray. Exceptions: NullPointerException: If a is null.IndexOutOfBoundsException: If start or count is negative, or if start + count is larger than the length of the given array, or if index is less than start or larger than start + count, or if codePointOffset is positive and the text range starting with index and ending with start + count – 1 has fewer than codePointOffset code points, or if codePointOffset is negative and the text range starting with start and ending with index – 1 has fewer than the absolute value of codePointOffset code points. Below program illustrate the Character.offsetByCodePoints() method: Java //Java program for offsetByCodePoints() method import java.lang.*; public class gfg { public static void main(String[] args) { // Creating a char array c_arr and assigning values char[] c_arr = new char[] {'g','e','e','k','s'}; // Integer primitives int s = 1; int c= 4; // Creating and assigning result of offsetByCodePoints // On subarray of c_arr to r int r = Character.offsetByCodePoints(c_arr, s, c, 1, 2); String st = "The index within the subarray is " + r; System.out.println(st); } } Output:The index within the subarray is 3 Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#offsetByCodePoints(char[],%20int,%20int,%20int,%20int) Comment More infoAdvertise with us Next Article Character.offsetByCodePoints() in Java with Examples T Twinkl Bajaj Follow Improve Article Tags : Misc Java Java-lang package Java-Functions Java-Character +1 More Practice Tags : JavaMisc Similar Reads Character.reverseBytes() in Java with examples The Character.reverseBytes() method in Java is a utility function from the java.lang.Character class. This method is used to reverse the order of the two bytes in a given 16-bit Unicode character (char). All Java characters are two bytes. It is useful when we work with systems or protocols that use 2 min read Character.offsetByCodePoints() Method in java 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 codeP 2 min read CharBuffer position() methods in Java with Examples The position(int newPosition) method of java.nio.CharBuffer Class is used to set this buffer's position. If the mark is defined and larger than the new position then it is discarded. Syntax: public CharBuffer position(int newPosition) Parameters: This method takes the newPosition as parameter which 2 min read CharacterIterator next() method in Java with Examples The next() method of java.text.CharacterIterator interface in Java is used to get the next character that is to be read by this CharacterIterator. This method decrements this iterator to one index forward and returns that next character. Syntax: public char next() Parameter: This method do not accep 1 min read CharBuffer charAt() methods in Java with Examples The charAt() method of java.nio.CharBuffer Class is used to read the character at the given index relative to the current position. Syntax: public final char charAt(int index) Parameters: This method takes the index of the character to be read, relative to the position; must be non-negative and smal 2 min read StringBuilder charAt() in Java with Examples The charAt(int index) method of StringBuilder Class is used to return the character at the specified index of String contained by StringBuilder Object. The index value should lie between 0 and length()-1. Syntax: public char charAt(int index) Parameters: This method accepts one int type parameter in 3 min read CharacterIterator setIndex() method in Java with Examples The setIndex() method of java.text.CharacterIterator interface in Java is used to set the current index that is to be read by this CharacterIterator. This method takes the index to be set as a parameter and sets the index of this CharacterIterator at that index and then it returns that character. Sy 1 min read CharacterIterator previous() method in Java with Examples The previous() method of java.text.CharacterIterator interface in Java is used to get the previous character that is to be read by this CharacterIterator. This method decrements this iterator to one index backwards and returns that previous character. Syntax: public char previous() Parameter: This m 1 min read Charset toString() method in Java with Examples The toString() method is a built-in method of the java.nio.charset returns a string which describes the charset involved. Syntax: public final String toString() Parameters: The function does not accepts any parameter. Return Value: The function returns a string describing this charset. Below is the 1 min read Like