java.lang.Character codePointBefore(char[] a, int index)


The Character.codePointBefore(char[] a, int index) java method returns the code point preceding the given index of the char array. If the char value at (index – 1) in the char array is in the low-surrogate range, (index – 2) is not negative, and the char value at (index – 2) in the char array is in the high-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, the char value at (index – 1) is returned.

Make a note that the codePointBefore method of Character class is static thus it should be accessed statically which means the we would be calling this method in this format:

Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java codePointBefore() method non statically.


The codePointBefore(char[] a, int index) method throws the following exception:

  • NullPointerException – if a is null.
  • IndexOutOfBoundsException – if the index argument is less than 1 or greater than the length of the char array

Method Syntax

public static int codePointBefore(char[] a, int index)

Method Argument

Data Type Parameter Description
char[] a the char array
int index the index following the code point that should be returned

Method Returns

The codePointBefore(char[] a, int index) method of Character class returns the Unicode code point value before the given index.


Requires Java 1.5 and up

Java Character codePointBefore(char[] a, int index) Example

Below is a simple java example on the usage of codePointBefore(char[] a, int index) method of Character class.

Sample Output

Below is the sample output when you run the above example.

java Character codePointBefore(char[] a, int index) example output