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); |
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.
public |
Parameter |
Description |
index |
An integer value indicating the index following the Unicode value that is to be returned. |
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 |