Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

codePointBefore()

Example

Provide the Unicode value of the initial character in a string (for instance, the Unicode value of “H” is 72).

String myStr = “Hello”;

int result = myStr.codePointBefore(1);System.out.println(result);

Definition and Usage

The codePointBefore() function retrieves the Unicode value of the character preceding the given index within a string.

The indexing starts from 1 for the first character, 2 for the second character, and so forth.

It’s important to note that providing an index of 0 will result in an error due to it being a negative number, which is out of bounds.

Syntax

public int codePointBefore(int index)

Parameter Values

Parameter

Description

index

An integer value indicating the index following the Unicode value that is to be returned.

Technical Details

Java 

An integer value representing the Unicode value preceding the specified index.

Throws

IndexOutOfBoundsException occurs if the index is negative or equal to or greater than the length of the specified string.

Java Version

1.5