Saturday, November 16, 2024
Google search engine
HomeLanguagesJavaBidi getLevelAt() method in Java with Examples

Bidi getLevelAt() method in Java with Examples

The getLevelAt() method of java.text.Bidi class is used to provide the resolved level of the particular character present at the particular point on the line of bidi text. Syntax:

public int getLevelAt(int offset)

Parameter: This method takes offset of the character present of the line of text for which resolved level is needed. Return Value: This method provides the resolved level for a particular character whose offset is given as parameter if the offset is less than zero or greater than the entire length of bidi text then it just returns the equivalent base level. Below are the examples to illustrate the getLevelAt() method: Example 1: 

Java




// Java program to demonstrate
// getLevelAt() method
 
import java.text.*;
import java.util.*;
import java.io.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing Bidi
        Bidi bidi = new Bidi("Geeks for Geeks", 0);
 
        int offset = 3;
 
        // getting resolved level of Character
        // using getLevelAt() method
        int status = bidi.getLevelAt(offset);
 
        // display the result
        if (offset > 0
            && (bidi.getLength()) > offset)
            System.out.println(
                "resolved level of the "
                + "Character at offset "
                + offset + " is "
                + status);
        else
            System.out.println(
                "base direction level is "
                + status);
    }
}


Output:

resolved level of the Character at offset 3 is 0

Example 2: 

Java




// Java program to demonstrate
// getLevelAt() method
 
import java.text.*;
import java.util.*;
import java.io.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing Bidi
        Bidi bidi = new Bidi("Tajmahal", 0);
 
        int offset = -3;
 
        // getting resolved level of Character
        // using getLevelAt() method
        int status = bidi.getLevelAt(offset);
 
        // display the result
        if (offset > 0
            && (bidi.getLength()) > offset)
            System.out.println(
                "resolved level of the "
                + "Character at offset "
                + offset + " is "
                + status);
        else
            System.out.println(
                "base direction level is "
                + status);
    }
}


Output:

base direction level is 0

Reference: https://docs.oracle.com/javase/9/docs/api/java/text/Bidi.html#getLevelAt-int-

RELATED ARTICLES

Most Popular

Recent Comments