Java Bidi getLength()方法及示例

来源:这里教程网 时间:2026-02-17 20:32:50 作者:

Java Bidi getLength()方法及示例

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

语法

public int getLength()

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

返回值 :该方法提供了bidi文本的 长度 ,为整数。

下面的例子说明了 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-

相关推荐