Signup/Sign In
LAST UPDATED: OCTOBER 20, 2020

Java Character getType(int codePoint) Method

Java getType(int codepoint) method is a part of Character class. This method returns the value that indicates the general category of the specified Unicode codepoint character value.

Note: This method is suitable for the supplementary as well as the non- supplementary characters.

Syntax:

public static int getType(int codePoint)  

Parameters:

The parameter passed is the Unicode codepoint character whose value of the general category will be returned.

Returns:

Returns the integer value representing the general category of the specified Unicode codepoint character.

Example 1:

Here, the integer values representing the general category of the specified Unicode codepoint characters are returned.

public class StudyTonight 
{
	public static void main(String[] args) 
	{
		int cp1 = 88;
		int cp2 = 2;
		int cp3 = 62;
		int cp4 = 101;
		int cp5 = 84;
		int n1 = Character.getType(cp1);
		int n2 = Character.getType(cp2);
		int n3 = Character.getType(cp3);
		int n4 = Character.getType(cp4);
		int n5 = Character.getType(cp5);
		System.out.println("The value of " + (char) cp1 + " is : " + n1);
		System.out.println("The value of " + (char) cp2 + " is : " + n2);
		System.out.println("The value of " + (char) cp3 + " is : " + n3);
		System.out.println("The value of " + (char) cp4 + " is : " + n4);
		System.out.println("The value of " + (char) cp5 + " is : " + n5);
	}
}


The value of X is : 1
The value of  is : 15
The value of > is : 25
The value of e is : 2
The value of T is : 1

Example 2:

Here is a general example where the user can enter the input of his choice and get the desired output.

import java.util.Scanner;
public class StudyTonight 
{
	public static void main(String[] args) 
	{
		try 
		{
			System.out.println("Enter the unicode codepoint character");
			Scanner sc = new Scanner(System. in );
			int cp = sc.nextInt();
			int r = Character.getType(cp);
			System.out.println("The character " + (char) cp + " has type value : " + r);
		}
		catch(Exception e) 
		{
			System.out.println("Invalid input");
		}
    }
}


Enter the unicode codepoint character
33
The character ! has type value : 24
*********************************************
Enter the unicode codepoint character
121
The character y has type value : 2

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.