📌  相关文章
📜  Java中的 Collator getDecomposition() 方法与示例

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

Java中的 Collator getDecomposition() 方法与示例

Java.text.Collator 类getDecomposition()方法用于获取此collator 的分解方式。
句法:

public int getDecomposition()

参数:此方法不接受任何参数。
返回值:该方法返回此collator的分解模式
以下是说明getDecomposition()方法的示例:
示例 1:

Java
// Java program to demonstrate
// getDecomposition() method
 
import java.text.*;
import java.util.*;
import java.io.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        try {
 
            // Creating and initializing
            // new simple rule
            String simple
                = "< a < b < c < d";
 
            // Creating and initializing
            // new RuleBasedCollator Object
            RuleBasedCollator col
                = new RuleBasedCollator(simple);
 
            // setting decomposition mode
            // into the Collator object
            col.setDecomposition(
                Collator.CANONICAL_DECOMPOSITION);
 
            // getting decompostiton mode
            // using getDecomposition() method
            int mode = col.getDecomposition();
 
            // display result
            if (mode == 0)
                System.out.println(
                    "decompostiton mode is"
                    + " :- NO_DECOMPOSITION");
            else if (mode == 1)
                System.out.println(
                    "decompostiton mode is "
                    + ":- CANONICAL_DECOMPOSITION");
            else
                System.out.println(
                    "decompostiton mode is "
                    + ":- FULL_DECOMPOSITION. ");
        }
 
        catch (ClassCastException e) {
 
            System.out.println("Exception thrown : " + e);
        }
        catch (ParseException e) {
 
            System.out.println("Exception thrown : " + e);
        }
    }
}


Java
// Java program to demonstrate
// getDecomposition() method
 
import java.text.*;
import java.util.*;
import java.io.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        try {
 
            // Creating and initializing
            // Collator Object
            Collator col
                = Collator.getInstance(Locale.UK);
 
            // getting decompostiton mode
            // using getDecomposition() method
            int mode = col.getDecomposition();
 
            // display result
            if (mode == 0)
                System.out.println(
                    "decompostiton mode is"
                    + " :- NO_DECOMPOSITION");
            else if (mode == 1)
                System.out.println(
                    "decompostiton mode is "
                    + ":- CANONICAL_DECOMPOSITION");
            else
                System.out.println(
                    "decompostiton mode is "
                    + ":- FULL_DECOMPOSITION. ");
        }
 
        catch (ClassCastException e) {
 
            System.out.println("Exception thrown : " + e);
        }
    }
}


输出:
decompostiton mode is :- CANONICAL_DECOMPOSITION

示例 2:

Java

// Java program to demonstrate
// getDecomposition() method
 
import java.text.*;
import java.util.*;
import java.io.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        try {
 
            // Creating and initializing
            // Collator Object
            Collator col
                = Collator.getInstance(Locale.UK);
 
            // getting decompostiton mode
            // using getDecomposition() method
            int mode = col.getDecomposition();
 
            // display result
            if (mode == 0)
                System.out.println(
                    "decompostiton mode is"
                    + " :- NO_DECOMPOSITION");
            else if (mode == 1)
                System.out.println(
                    "decompostiton mode is "
                    + ":- CANONICAL_DECOMPOSITION");
            else
                System.out.println(
                    "decompostiton mode is "
                    + ":- FULL_DECOMPOSITION. ");
        }
 
        catch (ClassCastException e) {
 
            System.out.println("Exception thrown : " + e);
        }
    }
}
输出:
decompostiton mode is :- NO_DECOMPOSITION

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