Java.lang.String.codePointBefore() Method

Advertisements


Description

The java.lang.String.codePointBefore() 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.

Declaration

Following is the declaration for java.lang.String.codePointBefore() method

public int codePointBefore(int index)

Parameters

  • index -- This is the index following the code point that should be returned.

Return Value

This method returns the Unicode code point value before the given index.

Exception

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

Example

The following example shows the usage of java.lang.String.codePointBefore() method.

package com.tutorialspoint;

import java.lang.*;

public class StringDemo {

  public static void main(String[] args) {
  
    String str = "JAVA";
    System.out.println("String = " + str);
        
    // codepoint before index 1 i.e J
    int retval = str.codePointBefore(1);
        
    // prints character before index1 in string
    System.out.println("Character(unicode point) = " + retval);
  }
}

Let us compile and run the above program, this will produce the following result:

String = JAVA
Character(unicode point) = 74



Advertisements
Advertisements