Java String.codePointBefore(int index) example

By Pooja Mane, Views 9, Date 17-May-2018

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.

Syntax

public int codePointBefore(int index)

Parameters

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

Returns

The Unicode code point value before the given index.

Throws

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);
    }
}

output

Character unicode before index 9 :- 108

Suggested Posts

Yashwant Chavan

Yashwant Chavan

Hi there! I am founder of technicalkeeda.com 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@gmail.com