java.lang.Character getDirectionality(char ch)
Description
This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the getDirectionality(int) method.
The getDirectionality(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.digit(char ch, int radix)
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 getDirectionality() method non statically.
Method Syntax
public static byte getDirectionality(char ch)
Method Argument
Data Type | Parameter | Description |
---|---|---|
char | ch | char for which the directionality property is requested. |
Method Returns
The getDirectionality(char ch) method of Character class returns byte which denotes the directionality property of the char value.
Compatibility
Requires Java 1.4 and up
Java Character getDirectionality(char ch) Example
Below is a simple java example on the usage of getDirectionality(char ch) method of Character class.
package com.javatutorialhq.java.examples; import java.util.Scanner; /* * This example source code demonstrates the use of * getDirectionality(char ch) method of Character class. */ public class CharacterGetDirectionalityCharExample { 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(); /* * byte value 0 represents DIRECTIONALITY_LEFT_TO_RIGHT */ // Unicode directionality property for the given character for (char ch : value) { byte result = Character.getDirectionality(ch); // print the result System.out.println("character " + ch + " Unicode directionality property is " + result); } // check in Character constant for equivalent } }
Sample Output
Below is the sample output when you run the above example.