Java.lang.Character.codePointAt() Method



Description

The java.lang.Character.codePointAt(CharSequence seq, int index) returns the code point at the given index of the CharSequence.

If the char value at the given index in the CharSequence is in the high-surrogate range, the following index is less than the length of the CharSequence, and the char value at the following index is in the low-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, the char value at the given index is returned.

Declaration

Following is the declaration for java.lang.Character.codePointAt() method

public static int codePointAt(CharSequence seq, int index)

Parameters

  • seq − a sequence of char values (Unicode code units)

  • index − the index to the char values (Unicode code units) in the char array to be converted

Return Value

This method returns the Unicode code point at the given index.

Exception

  • NullPointerException − if seq is null.

  • IndexOutOfBoundsException − if the value index is negative or not less than seq.length().

Example

The following example shows the usage of lang.Character.codePointAt() method.

package com.tutorialspoint;

import java.lang.*;

public class CharacterDemo {

   public static void main(String[] args) {

      // create a CharSequence seq and assign value
      CharSequence seq = "Hello";

      // create and assign value to index
      int index  = 4;

      // create an int res
      int res;

      // assign result of codePointAt on seq at index to res
      res = Character.codePointAt(seq, index);

      String str = "Unicode code point is " + res;

      // print res value
      System.out.println( str );
   }
}

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

Unicode code point is 111
java_lang_character.htm
Advertisements