Java Bidi createLineBidi()方法及示例

Java Bidi createLineBidi()方法及示例

java.text.Bidi 类的 createLineBidi() 方法用于创建一个新的bidi对象,该对象具有相同的基本方向,并代表当前bidi范围内的每个属性。

语法

public Bidi createLineBidi(int lineStart,
                           int lineLimit)

参数 :这个方法需要以下参数作为参数

  • lineStart : 它是这个新标的的起始点。
  • lineLimit : 它是这个新比迪的终点。

返回值: 该方法返回一个新的Bidi 对象

下面是一些例子来说明 createLineBidi() 方法。

例子 1 :

// Java program to demonstrate
// createLineBidi() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing Bidi
        // text with base direction
        Bidi bidi
            = new Bidi(
                "Geeks For Geeks",
                Bidi.DIRECTION_RIGHT_TO_LEFT);
  
        // creating and new bidi Object using the old one
        // using createLineBidi() method
        Bidi newbidi = bidi.createLineBidi(1, 6);
  
        // display the new bidi status
        System.out.println("New Bidi "
                           + "\nLength : "
                           + newbidi.getLength()
                           + "\nnumber of levels : "
                           + newbidi.getRunCount()
                           + "\nBase Level : "
                           + newbidi.getBaseLevel());
    }
}

输出:

New Bidi 
Length : 5
number of levels : 2
Base Level : 1

例2 :

// Java program to demonstrate
// createLineBidi() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing Bidi
        // text with base direction
        Bidi bidi
            = new Bidi("Tajmahal",
                       Bidi.DIRECTION_RIGHT_TO_LEFT);
  
        // creating and new bidi Object using the old one
        // using createLineBidi() method
        Bidi newbidi = bidi.createLineBidi(3, 5);
  
        // display the new bidi status
        System.out.println("New Bidi "
                           + "\nLength : "
                           + newbidi.getLength()
                           + "\nnumber of levels : "
                           + newbidi.getRunCount()
                           + "\nBase Level : "
                           + newbidi.getBaseLevel());
    }
}

输出:

New Bidi 
Length : 2
number of levels : 1
Base Level : 2

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程