Character 類的 getDirectionality(char ch) 方法用於返回給定字符的 unicode 方向性屬性。通常,字符方向性計算文本的視覺順序。 undefined char 值的方向性值為 DIRECTIONALITY_UNDEFINED。
用法
public static byte getDirectionality(char ch)
參數
ch:它是請求方向性屬性的字符。
返回值
它返回 char 值的方向性屬性。
例子1
public class JavaCharactergetDirectionalityExample1 {
public static void main(String[] args) {
// Create two character primitives obj1, obj2
char obj1, obj2;
// Assign the values to ch1, ch2
obj1 = 'Q';
obj2 = '1';
// create 2 byte primitives b1, b2
byte b1, b2;
// Assign the directionality of obj1 and obj2 to b1 and b2 respectively.
b1 = Character.getDirectionality(obj1);
b2 = Character.getDirectionality(obj2);
System.err.println("The directionality of " + obj1 + " is " + b1);
System.err.println("The directionality of " + obj2 + " is " + b2);
}
}
輸出:
The directionality of Q is 0 The directionality of 1 is 3
例子2
import java.util.Scanner;
public class JavaCharactergetDirectionalityExample2 {
public static void main(String[] args) {
// Ask the user for the first input.
System.out.print("Enter the first input:");
// Use scanner to get the user input
Scanner s1 = new Scanner(System.in);
// Gets the first user input
char[] value1 = s1.nextLine().toCharArray();
// The Unicode directionality property for the given character
for (char ch1:value1) {
byte result1 = Character.getDirectionality(ch1);
System.out.println("The Unicode directionality property for the character " + ch1+ " is " + result1);
}
// Ask the user for the sercond input.
System.out.print("Enter the second input:");
// use scanner to get the user input
Scanner s2 = new Scanner(System.in);
// gets the user input
char[] value2 = s2.nextLine().toCharArray();
// The Unicode directionality property for the given character
for (char ch2:value2) {
byte result2 = Character.getDirectionality(ch2);
System.out.println("The Unicode directionality property for the character " + ch2+ " is " + result2);
}
}
}
輸出:
Enter the first input:D The Unicode directionality property for the character D is 0 Enter the second input:4 The Unicode directionality property for the character 4 is 3
例子3
public class JavaCharactergetDirectionalityExample3 {
public static void main(String[] args)
{
// Create two int primitives ch1 and ch2 and assign values to them
int char1 = 45, char2 = 61;
// Assign the directionality
byte obj1 = Character.getDirectionality(char1);
byte obj2 = Character.getDirectionality(char2);
System.err.println("Directionality of first primitive is " + obj1);
System.err.println("Directionality of second primitive is " + obj2);
}
}
輸出:
Directionality of first primitive is 4 Directionality of second primitive is 13
Java 字符 getDirectionality() 方法
Character 類的 getDirectionality(int codePoint) 方法用於返回給定字符的 unicode 方向性屬性。通常,字符方向性用於計算文本的視覺順序。未定義字符值的方向性值為 DIRECTIONALITY_UNDEFINED。
用法
public static byte getDirectionality(int codePoint)
參數
上述方法隻需要一個參數:
codePoint: 它是請求方向性屬性的字符(Unicode 代碼點)。
返回值
getDirectionality(int codePoint) 方法返回字符的方向性屬性。
例子1
public class JavaCharactergetDirectionality_Example1 {
public static void main(String[] args) {
// Initialize the codePoints.
int codepoint1 = 36;
int codepoint2 = 2001;
// Convert the codePoint to its numeric value.
byte value1 = Character.getDirectionality(codepoint1);
byte value2 = Character.getDirectionality(codepoint2);
// Print the result.
System.out.println("codePoint:" + codepoint1);
System.out.println("Unicode directionality property for the first codePoint is:"+ value1);
System.out.println("codePoint:" + codepoint1);
System.out.println("Unicode directionality property for the second codePoint is:" + value2);
}
}
輸出:
codePoint:36 Unicode directionality property for the first codePoint is:5 codePoint:36 Unicode directionality property for the second codePoint is:1
例子2
public class JavaCharactergetDirectionality_Example2 {
public static void main(String[] args) {
// Create two int primitives cp1, cp2
int obj1, obj2;
// Assign the values to obj1, obj2
obj1 = 323;
obj2 = 60;
// create two byte primitives b1, b2
byte b1, b2;
// assign directionality of cp1, cp2 to b1, b2
b1 = Character.getDirectionality(obj1);
b2 = Character.getDirectionality(obj2);
System.err.println("Directionality for first codePoint is " + b1);
System.err.println("Directionality of second codePoint is " + b2);
}
}
輸出:
Directionality for first codePoint is 0 Directionality of second codePoint is 13
例子3
public class JavaCharactergetDirectionality_Example3 {
public static void main(String[] args) {
// Initialize the codePoints.
int codepoint1 = 36;
int codepoint2 = 2001;
int codepoint3 = 00;
// Convert the codePoint to its numeric value.
byte value1 = Character.getDirectionality(codepoint1);
byte value2 = Character.getDirectionality(codepoint2);
byte value3 = Character.getDirectionality(codepoint3);
// Print the result.
System.out.println("codePoint:" + codepoint1);
System.out.println("Unicode directionality property for the first codePoint is:"+ value1);
System.out.println("codePoint:" + codepoint2);
System.out.println("Unicode directionality property for the second codePoint is:" + value2);
System.out.println("codePoint:" + codepoint3);
System.out.println("Unicode directionality property for the second codePoint is:" + value3);
}
}
輸出:
codePoint:36 Unicode directionality property for the first codePoint is:5 codePoint:2001 Unicode directionality property for the second codePoint is:1 codePoint:0 Unicode directionality property for the second codePoint is:9
相關用法
- Java Character getType()用法及代碼示例
- Java Character getNumericValue()用法及代碼示例
- Java Character getType(char ch)用法及代碼示例
- Java Character getName()用法及代碼示例
- Java Character isLetter()用法及代碼示例
- Java Character isAlphabetic()用法及代碼示例
- Java Character isValidCodePoint()用法及代碼示例
- Java Character codePointCount()用法及代碼示例
- Java Character isISOControl()用法及代碼示例
- Java Character isSpace()用法及代碼示例
- Java Character toTitleCase()用法及代碼示例
- Java Character isMirrored()用法及代碼示例
- Java Character isBmpCodePoint()用法及代碼示例
- Java Character toUpperCase()用法及代碼示例
- Java Character isIdentifierIgnorable()用法及代碼示例
- Java Character isDigit()用法及代碼示例
- Java Character digit()用法及代碼示例
- Java Character toChars()用法及代碼示例
- Java Character compare()用法及代碼示例
- Java Character isLowerCase()用法及代碼示例
注:本文由純淨天空篩選整理自 Java Character getDirectionality() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。