Método CollationElementIterator getMaxExpansion() en Java con ejemplos

El método getMaxExpansion() de la clase java.text.CollationElementIterator se utiliza para obtener la expansión máxima que puede alcanzar cualquier final de secuencia especificado.
Sintaxis: 
 

public int getMaxExpansion(int order)

Parámetro : este método toma un elemento de colación como parámetro en formato entero para el cual se debe encontrar la longitud máxima
. Valor devuelto: este método devuelve la expansión máxima que puede alcanzar cualquier final de secuencia especificado.
A continuación se muestran los ejemplos para ilustrar el método getMaxExpansion() :
Ejemplo 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 result
            System.out.println("maximum expansion "
                               + "for order "
                               + i + " is "
                               + value);
        }
    }
}
Producción

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

Ejemplo 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 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 result
            System.out.println("maximum expansion"
                               + " for order "
                               + i + " is "
                               + value);
        }
    }
}
Producción

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

Referencia: https://docs.oracle.com/javase/9/docs/api/java/text/CollationElementIterator.html#getMaxExpansion-int-
 

Publicación traducida automáticamente

Artículo escrito por RohitPrasad3 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *