Facebook Page Twitter Page LinkedIn Page
× Java Tutorial Java Advanced Java Resources


The Java string codePointBefore() method is used to return the character (Unicode code point) before the specified index in the given string. An index argument must be in the ranges from 1 to length().

Syntax

public int codePointBefore(int index)

Parameters

index specify the index number following the code point that should be returned.

Return Value

Returns the character (Unicode code point) before the specified index in the given string.

Exception

throws IndexOutOfBoundsException, if the index argument is less than 1 or greater than the length of the string.

Example:

In the below example, codePointBefore() method is used to return the character (Unicode code point) before the specified index in the string called MyString.

public class MyClass {
  public static void main(String[] args) {
    String MyString = "Hello World!.";
    System.out.println(MyString.codePointBefore(5));   
  }
}

The output of the above code will be:

111

❮ Java String Methods