Java String.codePointBefore(int index) example

By Yashwant Chavan, Views 26, Last updated on 02-Apr-2019

In this java tutorial, You will learn how to use codePointBefore(int index) method of String class. This method, Returns the character (Unicode code point) before the specified index. The index refers to char values (Unicode code units) and ranges from 1 to length. If the char value at (index - 1) is in the low-surrogate range, (index - 2) is not negative, and the char value at (index - 2) is in the high-surrogate range, then the supplementary code point value of the surrogate pair is returned. If the char value at index - 1 is an unpaired low-surrogate or a high-surrogate, the surrogate value is returned.

tags Java

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


public int codePointBefore(int index)


index - The index following the code point that should be returned.


The Unicode code point value before the given index.


IndexOutOfBoundsException - if the index argument is less than 1 or greater than the length of this string.

Java String codePointBefore(int index) example

  • Assign String value.
  • value.codePointBefore(9);It will return the code point value before index 9.
  • Print the code point value.
package com.technicalkeeda;

public class App {

    public static void main(String[] args) {

        String value = "Technicalkeeda";

        int result = value.codePointBefore(9);

        System.out.println("Character unicode before index 9 :- " + result);


Character unicode before index 9 :- 108

Suggested Posts



Hi there! I am founder of and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][]