java.lang.Character getDirectionality(int codePoint)

Description

The Character.getDirectionality(int codePoint) java method returns the Unicode directionality property for the given character (Unicode code point). Character directionality is used to calculate the visual ordering of text. The directionality value of undefined character is DIRECTIONALITY_UNDEFINED.

The getDirectionality(int codepoint) 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.getDirectionality(int codePoint)

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(int codePoint)

Method Argument

Data Type Parameter Description
int codepoint the character (Unicode code point) for which the directionality property is requested.

Method Returns

The getDirectionality(int codePoint) method of Character class returns byte which denotes the directionality property of the character.

Compatibility

Requires Java 1.5 and up

Java Character getDirectionality(int codePoint) Example

Below is a simple java example on the usage of getDirectionality(int codePoint) method of Character class.

package com.javatutorialhq.java.examples;

/*
 * This example source code demonstrates the use of 
 * getDirectionality(int codePoint) method of Character class.
 */

public class CharacterGetDirectionalityCodepointExample {

	public static void main(String[] args) {

		// initialize a codepoint
		int codepoint1 = 65;
		int codepoint2 = 1791;


		// convert the code point to its numeric value
		byte value1 = Character.getDirectionality(codepoint1);
		byte value2 = Character.getDirectionality(codepoint2);

		// print the result
		System.out.println("unicodepoint '" + codepoint1 
				+ "' Unicode directionality property is " + value1);
		System.out.println("unicodepoint '" + codepoint2 
				+ "' Unicode directionality property is " + value2);
		
		
		/*
		 * byte value 0 represents DIRECTIONALITY_LEFT_TO_RIGHT byte value 2
		 * represents DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC
		 */
		
	}

}

Sample Output

Below is the sample output when you run the above example.

java Character getDirectionality(int codepoint) example output