Javatpoint Logo
Javatpoint Logo

Java Character codePointBefore() Method

This Method has 3 types of syntax.

Java codePointBefore(char[] a, int index) method

The codePointBefore(char[] a, int index) method of Character class returns the code point for the given index of the char array. If the char value at (index-1) in the char array is in the low surrogate range, index-2 is not negative. If the char value at (index-2) in the char array is in the high surrogate range, the supplementary code point to this surrogate pair is returned. Otherwise, the char value at (index-1) is returned.

Syntax

Parameter

The above method requires two parameters:

  • The char array
  • The index to the char value in the array that needs to be returned.

Return Value

The codePointBefore(char[] a, int index) method returns the Unicode point before the given index.

Example 1

Test it Now

Output:

Welcome to java tutorials.
The unicode point is given as = 87

Example 2

Test it Now

Output:

Welcome to java tutorials.
Unicode code point before the string is 87
The numbers are:  '1', '2', '3', '4', '5' 
Unicode code point before the number is 108

Example 3

Output:

Enter the desired index: 3
Result is given by:39

Java Character codePointBefore(char[] a, int index, int start)Method

The codePointBefore(char[] a, int index, int start) method of Character class is used to return the code point preceding the given index of the char array where only those array elements with index greater than or equal to start can be used. If in the char array, the char value at (index-1) is in the low surrogate range, (index-2) is not less than start. On the other hand, if the char value at (index-2) is in the high surrogate range, the supplementary code point corresponding to the surrogate pair is returned. Otherwise, it returned the char value at (index-1).

Syntax

Parameter

The above method requires three parameters:

  • The char array.
  • The index with the code point that should need to be returned.
  • The start is the index of the first array element in the char array.

Return Value

The codePointBefore(Char[] a, int index, int start) method returns the Unicode code point before the index.

Example 4

Test it Now

Output:

Welcome to our tutorial site.
The unicode code point is 67

Example 5

Test it Now

Output:

Welcome to our tutorial site.
The unicode code point for alphabets:
The unicode code point is 67
The unicode code point for numbers:
The unicode code point is 51

Example 6

Test it Now

Output:

The numbers are: '1', '2', '3', '4'
The unicode code point is 51
The numbers are: '5', '6', '7', '8'
The unicode code point is 55

Java Character codePointBefore(charSequence seq, int index) Method

The codePointBefore(charSequence seq, int index) method of Character class is used to return the code point preceding the given index of the charSequence. If in the char sequence, the char value at (index-1) is in the low surrogate range, (index-2) is not negative. On the other hand, if the char value at (index-2) is in the high surrogate range, the supplementary code point corresponding to this surrogate pair is returned. Otherwise, the char value at (index-1) is returned.

Syntax

Parameter

The above method requires two parameters:

  • The charSequence instance.
  • The index with the code point that needs to be returned.

Return Value

The codePointBefore(charaSequence seq, int index) method returns the Unicode code point value before the given index.

Example 7

Test it Now

Output:

Welcome to our tutorial site:
The Unicode code point for Java is 108
The Unicode code point for Everyone is 101

Example 8

Test it Now

Output:

The string is: Java
The Unicode code point for Java is 108
The numbers are: '1', '2', '3', '4'
The unicode code point for numbers is 108

Example 9

Test it Now

Output:

The numbers are: '1', '2', '3', '4':
The unicode code point for first four numbers is 51
The numbers are: '1', '2', '3', '4':
The unicode code point for second four numbers is 55
Next TopicJava Character



Help Others, Please Share

facebook twitter pinterest