Signup/Sign In

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

Java codePointAt() method is a part of Character class. This method returns the codepoint at the index specified of the char array where the element with the index less than the specified limit is used. If at a particular index, the char value at a given index is in the low surrogate range then the codepoint corresponding to this pair will be returned else if the char value in the char array is in the high surrogate range, the following index is less than the limit specified.


public static int codePointAt(char[] a, int index,int limit)  


The parameters passed are:

  • char array

  • int index to the char value in the char array

  • int limit which is the last index that can be used of the char array.


Returns the codepoint value of the character at the passed index.

Example 1:

Here, the codepoint value of the character at the specified index is returned.

public class StudyTonight
  public static void main(String args[])
    char[] ch1 = new char[] { 'm', 'o', 'h', 'i', 't' };  
    System.out.println("The input is : Mohit");  

    int i1  = 2, l1 = 4;  
    int r1 = Character.codePointAt(ch1, i1, l1);  

    System.out.println("Unicode code point is : " + r1 );  
    char[] ch2 = new char[] { 's', 't', 'u', 'd', 'y','t', 'o', 'n','i','g','h','t' };  
    System.out.println("The input is : StudyTonight");  

    int i2  = 2, l2 = 3;  
    int r2 = Character.codePointAt(ch2, i2, l2);  
    System.out.println("Unicode code point is : " + r2 );

The input is : Mohit
Unicode code point is : 104
The input is : StudyTonight
Unicode code point is : 117

Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the desired output.

import java.lang.Character;
import java.util.Scanner;

public class StudyTonight
    public static void main(String[] args) 
          System.out.println("Enter char array");
          Scanner sc = new Scanner(;
          char []ch = sc.nextLine().toCharArray();
          System.out.println("Enter index");
          int n = sc.nextInt();
          System.out.println("Enter limit");
          int l = sc.nextInt();
          System.out.println("The codepoint value is : " +Character.codePointAt(ch,n,l));  
        catch(Exception e)
          System.out.println("Invalid Input");

Enter char array
Enter index
Enter limit
The codepoint value is : 104
Enter char array
java is love
Enter index
Enter limit
The codepoint value is : 115
Enter char array
Enter index
Enter limit
Invalid Input

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.

About the author:
A Computer Science and Engineering Graduate(2016-2020) from JSSATE Noida. JAVA is Love. Sincerely Followed Sachin Tendulkar as a child, M S Dhoni as a teenager, and Virat Kohli as an adult.