java.lang.Character getType(char ch)
Description
This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the getType(int) method.
The getType(char ch) method of Character class is static thus it should be accessed statically which means the we would be calling this method in this format:
Character.getType(char ch)
Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java getType()Â method non statically.
Method Syntax
public static int getType(char ch)
Method Argument
| Data Type | Parameter | Description |
|---|---|---|
| char | ch | the character to be tested. |
Method Returns
The getType(char ch) method of Character class returns a value of type int representing the character’s general category.
Compatibility
Requires Java 1.1 and up
Java Character getType(char ch) Example
Below is a simple java example on the usage of getType(char ch) method of Character class.
package com.javatutorialhq.java.examples;
import java.util.Scanner;
/*
* This example source code demonstrates the use of
* getType(char ch) method of Character class.
*/
public class CharacterGetTypeCharExample {
public static void main(String[] args) {
// Ask for user input
System.out.print("Enter an input:");
// use scanner to get the user input
Scanner s = new Scanner(System.in);
// gets the user input
char[] value = s.nextLine().toCharArray();
// close the scanner object
s.close();
// get a value indicating a character's general category
for (char ch : value) {
int result = Character.getNumericValue(ch);
// print the result
System.out.println("character " + ch
+ " general category is " + result);
}
// please refer to Character constants
}
}
Sample Output
Below is the sample output when you run the above example.
