Java 中的 collectionlementiterator getMaxExpansion()方法,带示例

原文:https://www . geeksforgeeks . org/collectionelementiterator-getmaxexpansion-method-in-Java-with-examples/

Java . text . collectionelementiterator 类getMaxExpansion() 方法用于获取任意指定序列结尾可以达到的最大扩展。 语法:

public int getMaxExpansion(int order)

参数:该方法以整数格式的排序元素为参数,必须找到最大长度 返回值:该方法返回任意指定序列结尾可以达到的最大展开。 以下是举例说明 getMaxExpansion() 方法: 例 1:

Java 语言(一种计算机语言,尤用于创建网站)

// Java program to demonstrate
// getMaxExpansion() method

import java.text.*;
import java.util.*;
import java.io.*;

public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing testString
        String test = "GeeksForGeeks";

        // creating and initializing
        // RuleBasedCollator object
        RuleBasedCollator rbc
            = (RuleBasedCollator)(Collator.getInstance());

        // creating and initializing
        // CollationElementIterator
        CollationElementIterator cel
            = rbc.getCollationElementIterator(test);

        // for iteration
        for (int i = 1; i <= test.length(); i++) {

            // getting maximum expansion
            // using getMaxExpansion() method
            int value
                = cel.getMaxExpansion(cel.next());

            // display the reslut
            System.out.println("maximum expansion "
                               + "for order "
                               + i + " is "
                               + value);
        }
    }
}

Output

maximum expansion for order 1 is 1
maximum expansion for order 2 is 1
maximum expansion for order 3 is 1
maximum expansion for order 4 is 1
maximum expansion for order 5 is 1
maximum expansion for order 6 is 1
maximum expansion for order 7 is 1
maximum expansion for order 8 is 1
maximum expansion for order 9 is 1
maximum expansion for order 10 is 1
maximum expansion for order 11 is 1
maximum expansion for order 12 is 1
maximum expansion for order 13 is 1

例 2:

Java 语言(一种计算机语言,尤用于创建网站)

// Java program to demonstrate
// getMaxExpansion() method

import java.text.*;
import java.util.*;
import java.io.*;

public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing testString
        String test
            = "Code Geeks 123";

        // creating and intiallizing
        // RuleBasedCollator object
        RuleBasedCollator rbc
            = (RuleBasedCollator)(Collator
                                      .getInstance());

        // creating and initializing
        // CollationElementIterator
        CollationElementIterator cel
            = rbc.getCollationElementIterator(test);

        // for iteration
        for (int i = 1; i <= test.length(); i++) {

            // getting maximum expansion
            // using getMaxExpansion() method
            int value
                = cel.getMaxExpansion(cel.next());

            // display the reslut
            System.out.println("maximum expansion"
                               + " for order "
                               + i + " is "
                               + value);
        }
    }
}

Output

maximum expansion for order 1 is 1
maximum expansion for order 2 is 1
maximum expansion for order 3 is 1
maximum expansion for order 4 is 1
maximum expansion for order 5 is 1
maximum expansion for order 6 is 1
maximum expansion for order 7 is 1
maximum expansion for order 8 is 1
maximum expansion for order 9 is 1
maximum expansion for order 10 is 1
maximum expansion for order 11 is 1
maximum expansion for order 12 is 1
maximum expansion for order 13 is 1
maximum expansion for order 14 is 1

参考:https://docs . Oracle . com/javase/9/docs/API/Java/text/collectionelementtiterator . html # getMaxExpansion-int-