LAST UPDATED: OCTOBER 16, 2020
Java Character codePointAt(CharSequence seq, int index) Method
Java codePointAt()
method is a part of Character
class. This method returns the codepoint at the index specified of the Character Sequence.If the charvalue in the charSequence at a particular index is in the high surrogate range, the following index would be lesser than the length of the charSequence else 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:
public static int codePointAt(CharSequence seq, int index)
Parameter:
The parameter passed is a
Returns:
Returns the codepoint value of the character at the passed index.
Example 1:
Here, the codepoint value of the char sequence at the specified index is returned.
import java.lang.Character;
public class StudyTonight
{
public static void main(String[] args)
{
CharSequence s = "Welcome to StudyTonight";
System.out.println("Input String is : " +s);
int index = 4;
System.out.println("The codePoint value is : " +Character.codePointAt(s,index));
}
}
Input String is : Welcome to StudyTonight
The codePoint value is : 111
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)
{
try
{
System.out.println("Enter charSequence");
Scanner sc = new Scanner(System.in);
CharSequence s = sc.nextLine();
System.out.println("Enter index");
int n = sc.nextInt();
System.out.println("The codepoint value is : " +Character.codePointAt(s,n));
}
catch(Exception e)
{
System.out.println("Invalid Input");
}
}
}
Enter charSequence
mohit
Enter index
2
The codepoint value is : 104
**********************************
Enter charSequence
god is great
Enter index
4
The codepoint value is : 105
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.