Open In App

Collator getDecomposition() method in Java with Example

Last Updated : 23 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The getDecomposition() method of java.text.Collator class is used to get the decomposition mode of this collator .
Syntax: 

public int getDecomposition()

Parameter: This method does not accept any parameter.
Return Value: This method returns the decomposition mode of this collator.
Below are the examples to illustrate the getDecomposition() method:
Example 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 decomposition mode
            // using getDecomposition() method
            int mode = col.getDecomposition();
 
            // display result
            if (mode == 0)
                System.out.println(
                    "decomposition mode is"
                    + " :- NO_DECOMPOSITION");
            else if (mode == 1)
                System.out.println(
                    "decomposition mode is "
                    + ":- CANONICAL_DECOMPOSITION");
            else
                System.out.println(
                    "decomposition mode is "
                    + ":- FULL_DECOMPOSITION. ");
        }
 
        catch (ClassCastException e) {
 
            System.out.println("Exception thrown : " + e);
        }
        catch (ParseException e) {
 
            System.out.println("Exception thrown : " + e);
        }
    }
}


Output: 

decomposition mode is :- CANONICAL_DECOMPOSITION

 

Example 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 decomposition mode
            // using getDecomposition() method
            int mode = col.getDecomposition();
 
            // display result
            if (mode == 0)
                System.out.println(
                    "decomposition mode is"
                    + " :- NO_DECOMPOSITION");
            else if (mode == 1)
                System.out.println(
                    "decomposition mode is "
                    + ":- CANONICAL_DECOMPOSITION");
            else
                System.out.println(
                    "decomposition mode is "
                    + ":- FULL_DECOMPOSITION. ");
        }
 
        catch (ClassCastException e) {
 
            System.out.println("Exception thrown : " + e);
        }
    }
}


Output: 

decompostiton mode is :- NO_DECOMPOSITION

 

Reference: https://docs.oracle.com/javase/9/docs/api/java/text/Collator.html#getDecomposition–



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads