Java Bidi isRightToLeft()方法及示例

Java Bidi isRightToLeft()方法及示例

java.text.Bidi 类的 isRightToLeft() 方法是用来检查它是否有从右到左的线条和底层方向。

语法

public boolean isRightToLeft()

参数 :这个方法不接受任何参数。
返回值: 如果这个bidi有从右到左的线和底层方向,这个方法返回 ,否则返回
以下是说明 isRightToLeft( )方法的例子:

例子1

// Java program to demonstrate
// isRightToLeft() method
 
import java.text.*;
import java.util.*;
import java.io.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing Bidi
        // with base direction
        Bidi bidi
            = new Bidi(
                "Geeks For Geeks",
                Bidi.DIRECTION_LEFT_TO_RIGHT);
 
        // checking both line and base direction
        // using isRightToLeft() method
        boolean status = bidi.isRightToLeft();
 
        // display the result
        if (status)
            System.out.println(
                "Both Line and Base "
                + "direction is right to left");
        else
            System.out.println(
                "Both Line and Base "
                + "direction is not right to left");
    }
}

输出

Both Line and Base direction is not right to left 

例2 :

// Java program to demonstrate
// isRightToLeft() method
 
import java.text.*;
import java.util.*;
import java.io.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing
        // AttributedString Object
        AttributedString attr
            = new AttributedString("GEEkS");
 
        // adding attribute of language
        // using addAttribute() method
        attr.addAttribute(
            AttributedCharacterIterator
                .Attribute
                .LANGUAGE,
            new Locale("ar_QA"));
 
        // creating and initializing Bidi
        // with AttributedCharacterIterator
        Bidi bidi = new Bidi(attr.getIterator());
 
        // checking both line and base direction
        // using isRightToLeft() method
        boolean status = bidi.isRightToLeft();
 
        // display the result
        if (status)
            System.out.println(
                "Both Line and Base "
                + "direction is right to left");
        else
            System.out.println(
                "Both Line and Base "
                + "direction is not right to left");
    }
}

输出

Both Line and Base direction is not right to left 

参考资料: https://docs.oracle.com/javase/9/docs/api/java/text/Bidi.html#isRightToLeft-

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程