Skip to content
Related Articles

Related Articles

Improve Article

Bidi isRightToLeft() method in Java with Examples

  • Last Updated : 27 Nov, 2019

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 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 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 langugae
        // using addAttribute() mehtod
        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–

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :