Signup/Sign In

Java Character codePointOf() Method

Java codePointOf() method is a part of Character class. This method returns the code point value of the Unicode character specified by the given Unicode character name.

Syntax:

public static int codePointOf(String name)

Parameter:

The parameter passed is the Unicode character name of which codepoint is to be returned.

Returns:

Returns the code point value of the character specified by the parameter.

Exceptions:

  • IllegalArgumentException - if the specified name is not a valid Unicode character name.
  • NullPointerException - if name is null

Example 1:

Here, the specified names are passed and the codepoint value assigned is returned.

import java.lang.Character;
public class StudyTonight
{    
	public static void main(String [] args)throws Exception
	{             
		int cp1 = Character.codePointOf("LATIN SMALL LETTER A WITH DIAERESIS");  
		System.out.println("The codePoint is : "+cp1);  

		int cp2 = Character.codePointOf("RIGHT SQUARE BRACKET");  
		System.out.println("The codePoint is : "+cp2);

		int cp3 = Character.codePointOf("LATIN CAPITAL LETTER E");  
		System.out.println("The codePoint is : "+cp3);

		int cp4 = Character.codePointOf("DIGIT SEVEN");  
		System.out.println("The codePoint is : "+cp4);
	}   
}


The codePoint is : 228
The codePoint is : 93
The codePoint is : 69
The codePoint is : 55

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)throws Exception
	{   
		try
		{
			System.out.println("Enter Name:");
			Scanner sc = new Scanner(System.in);
			String s = sc.nextLine();

			System.out.println("The codepoint count is : " +Character.codePointOf(s));            
		}
		catch(Exception e)
		{
			System.out.println("Invalid Input");
		} 
	}    
}


Enter Name:
DIGIT EIGHT
The codepoint count is : 56
***********************************
Enter Name:
LEFT SQUARE BRACKET
The codepoint count is : 91
***********************************
Enter Name:
mohit
Invalid Input



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.