Java.lang.Character.getType() Method



The java.lang.Character.getType(int codePoint) returns a value indicating a character's general category.


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

public static int getType(int codePoint)


  • codePoint - the character (Unicode code point) to be tested

Return Value

This method returns a value of type int representing the character's general category.


  • NA


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

package com.tutorialspoint;

import java.lang.*;

public class CharacterDemo {

   public static void main(String[] args) {

      // create 2 int primitives cp1, cp2
      int cp1, cp2;

      // assign values to cp1, cp2
      cp1 = 0x0034;
      cp2 = 0x006f;

      // create 2 int primitives i1, i2
      int i1, i2;

      // assign getType values of cp1, cp2 to i1, i2
      i1 = Character.getType(cp1);
      i2 = Character.getType(cp2);

       *  value 9 represents DECIMAL_DIGIT_NUMBER
       *  value 2 represents LOWERCASE_LETTER

      String str1 = "Category of cp1 is " + i1;
      String str2 = "Category of cp2 is " + i2;

      // print i1, i2 values
      System.out.println( str1 );
      System.out.println( str2 );

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

Category of cp1 is 9
Category of cp2 is 2