Java Data Type Tutorial - Java String.offsetByCodePoints(int index, int codePointOffset)








Syntax

String.offsetByCodePoints(int index, int codePointOffset) has the following syntax.

public int offsetByCodePoints(int index,   int codePointOffset)

Example

In the following code shows how to use String.offsetByCodePoints(int index, int codePointOffset) method.

/*from   w  ww  .ja va  2s .c  om*/

public class Main {

  public static void main(String[] args) {
  
    String str = "java2s.com";
    System.out.println("string = " + str);

    // returns the index within this String
    int retval = str.offsetByCodePoints(2, 4);
    // prints the index
    System.out.println("index = " + retval);
  }
}

The code above generates the following result.