Open In App

Bidi isRightToLeft() method in Java with Examples

Last Updated : 18 Jan, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The isRightToLeft() method of java.text.Bidi class is used to check if it has right to left line and base direction both or not.
Syntax: 

public boolean isRightToLeft()

Parameter: This method accepts nothing as parameter.
Return Value: This method return true if this bidi has both right to left line and base direction otherwise false.
Below are the examples to illustrate the isRightToLeft() method:
Example 1:  

Java




// 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");
    }
}


Output: 

Both Line and Base direction is not right to left 

 

Example 2: 

Java




// 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");
    }
}


Output: 

Both Line and Base direction is not right to left 

 

Reference: https://docs.oracle.com/javase/9/docs/api/java/text/Bidi.html#isRightToLeft–



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads