📜  Java中的双向 getLength() 方法和示例

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

Java中的双向 getLength() 方法和示例

Java.text.Bidi类的getLength()方法用于获取此Bidi 实例中文本的长度。

句法:

public int getLength()

参数:此方法不接受任何参数。

返回值:此方法以整数形式提供双向文本的长度

以下是说明getLength()方法的示例:

示例 1:

// Java program to demonstrate
// getLength() 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);
  
        // getting the length of line of text
        // using getLength() method
        int length = bidi.getLength();
  
        // display the result
        System.out.println("length of line : "
                           + length);
    }
}
输出:
length of line : 15

示例 2:

// Java program to demonstrate
// getLength() 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);
  
        // getting the length of line of text
        // using getLength() method
        int length = bidi.getLength();
  
        // display the result
        System.out.println("length of line : "
                           + length);
    }
}
输出:
length of line : 8

参考: https://docs.oracle.com/javase/9/docs/api/ Java/text/Bidi.html#getLength–