Related Articles

Related Articles

Collator setDecomposition() method in Java with Example
  • Last Updated : 03 Jan, 2020

The setdecomposition() method of java.text.Collator class is used to set the decomposition mode of this collator.

Syntax:

public void setDecomposition(int decompositionMode)

Parameter: This method takes the integer value as a parameter which represents the equivalent decomposition mode for this collator.

Return Value: This method has nothing to return.

Below are the examples to illustrate the setDecomposition() method:



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// setDecomposition() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        try {
  
            // Creating and initalizing 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
            // using setDecomposition() mehtod
            col.setDecomposition(
                Collator.CANONICAL_DECOMPOSITION);
  
            // getting decompostiton mode
            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);
        }
    }
}

chevron_right


Output:

decompostiton mode is :- CANONICAL_DECOMPOSITION

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// setDecomposition() 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);
  
            // setting decomposition mode
            // into the Collator object
            // using setDecomposition() mehtod
            col.setDecomposition(Collator.FULL_DECOMPOSITION);
  
            // getting decompostiton mode
            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);
        }
    }
}

chevron_right


Output:

decompostiton mode is :- FULL_DECOMPOSITION. 

Reference: https://docs.oracle.com/javase/9/docs/api/java/text/Collator.html#setDecomposition-int-

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up
Recommended Articles
Page :