Java Character getType() method Example

Many methods exist in java.lang.Character class used for different purposes. Some methods are useful for checking the character is a digit or letter or is a uppercase letter or lowercase letter etc. At the sametime, some methods can modify the case of the letters from uppercase to lowercase or vice versa.

Now the present method getType(char ch) returns an integer value of unicode’s representation of the character ch.

Following is the method signature as defined in java.lang.Character class.

  • public static int getType(char ch): Returns an integer value of char ch representing in unicode general category.
Following on Java Character getType() method Example illustrates. Just for interest, different types of characters are checked.
public class CharacterFunctionDemo
 public static void main(String args[])
  System.out.println("Integer values of different characters representing in unicode general category");  
  System.out.println("A represents: " + Character.getType('A'));  
  System.out.println("a represents: " + Character.getType('a'));  
  System.out.println("K represents: " + Character.getType('K'));  
  System.out.println("k represents: " + Character.getType('k'));  
  System.out.println("5 represents: " + Character.getType('5'));    
  System.out.println("2 represents: " + Character.getType('2'));  
  System.out.println("{ represents: " + Character.getType('{'));  
  System.out.println("* represents: " + Character.getType('*')); 
  System.out.println("@ represents: " + Character.getType('@'));   
  System.out.println("+ represents: " + Character.getType('+'));  
  System.out.println("$ represents: " + Character.getType('$'));  

Java Character getType() method Example

Try with other Character methods also for more confidence on Java coding.

Leave a Comment

Your email address will not be published.