📜  Java中的 Bidi getRunLevel() 方法及示例

📅  最后修改于: 2022-05-13 01:55:34.459000             🧑  作者: Mango

Java中的 Bidi getRunLevel() 方法及示例

Java.text.Bidi类的getRunLevel()方法用于为这行文本的第 n 次运行提供级别,如果只有一个运行状态,它将为该状态提供基本级别。

句法:

public int getRunLevel(int run)

参数:此方法接受要为其检索运行级别的逻辑运行的索引

返回值:此方法提供文本行中特定运行的级别

下面是说明getRunLevel()方法的示例:

示例 1:

// Java program to demonstrate
// getRunLevel() 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",
                Bidi.DIRECTION_RIGHT_TO_LEFT);
  
        // index for which level is needed
        int index = 0;
  
        // getting the level of run
        // using getRunLevel() method
        int level = bidi.getRunLevel(index);
  
        // display the result
        System.out.println(
            "level of first run is : "
            + level);
    }
}
输出:
level of first run is : 2

示例 2:

// Java program to demonstrate
// getRunLevel() 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",
                Bidi.DIRECTION_LEFT_TO_RIGHT);
  
        // index for which level is needed
        int index = 0;
  
        // getting the level of run
        // using getRunLevel() method
        int level = bidi.getRunLevel(index);
  
        // display the result
        System.out.println(
            "level of first run is : "
            + level);
    }
}
输出:
level of first run is : 0

参考: https://docs.oracle.com/javase/9/docs/api/ Java/text/Bidi.html#getRunLevel-int-