Javatpoint Logo
Javatpoint Logo

Java Character codePointAt() method

This Method has 3 types of syntax.

Java Character codePointAt(char[] a, int index) method

The codePointAt() method of Character class is used to return the code point at the given index of char array. If at a particular index, the char value in the char array is in the high surrogate range, the following index is less than the index of char array and if the char value at a given index is in the low surrogate range then the codepoint corresponding to this pair is returned.

Syntax

Parameter

The above method requires two parameters:

  • The char array
  • The index to the char value in the array.

Return Value

The codePointAt() method returns the value of character at the index.

Example 1

Test it Now

Output:

This is the first program for the given method :
32

Example 2

Test it Now

Output:

Given String : javatpoint.com
Character Value = 97
Character Value = 105

Example 3

Test it Now

Output:

The first string is = JAVA
Character(unicode point) = 65
The second string is = TPOINT
Character(unicode point) = 86

Example 4

Output:

Java is a unique language.
Enter the desired index: 8
Result:  97

Java Character codePointAt(char[] a, int index, int limit) method

The codePointAt(char[] a, int index, int limit) method of character class returns the code point at a given index of char array, where only element with index less than limit can be used. If at a particular index, the char value in the char array is in the high surrogate range, the following index is less than the limit. If the char value at a given index is in the low surrogate range, the code point corresponding to this pair is returned.

Syntax

Parameter

The above method requires three parameters:

  • The char array
  • The index to the char value in the array.
  • The limit is the index after the last element that can be used in the array.

Return Value

This method returns the Unicode point at the given index.

Example 5

Test it Now

Output:

Hello
Unicode code point is : 108
Everyone
Unicode code point is : 108

Example 6

Test it Now

Output:

The numbers are:  '1', '2', '3', '4', '5' 
Unicode code point is 50

Example 7

Test it Now

Output:

Hello
Unicode code point for Hello is 108
The numbers are:  '1', '2', '3', '4', '5' 
Unicode code point for number is 108

Java Character codePointAt(CharSequence seq, int index) Method

The codePointAt(CharSequence seq, int index) method of Character class returns the code point at a particular index of the charSequence. If at a particular index, the char value in the charSequence is in the high surrogate range, the following index would be lesser than the length of the charSequence. On the other hand, if the char value in the charSequence is in the low surrogate range, the supplementary code point corresponding to the given surrogate pair is returned.

Syntax

Parameter

The above method requires two parameters:

  • A sequence of char values.
  • The index of the char values which is to be converted in seq.

Return Value

This method returns the Unicode code point at a particular index.

Example 8

Test it Now

Output:

Java is secured
The Unicode code point is 97

Example 9

Test it Now

Output:

Java is secured
The Unicode code point for Java is 118
The numbers are:  '1', '2', '3', '4', '5' 
The Unicode code point for number is 52

Example 10

Test it Now

Output:

Java is more portable
The Unicode code point for Java is 118
Java is based on the concepts of OOPS.
The Unicode code point for Java is 118
Next TopicJava Character



Help Others, Please Share

facebook twitter pinterest