Collator setDecomposition() method in Java with Example
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:
Java
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
try {
String simple = "< a < b < c < d" ;
RuleBasedCollator col
= new RuleBasedCollator(simple);
col.setDecomposition(
Collator.CANONICAL_DECOMPOSITION);
int mode = col.getDecomposition();
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
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
try {
String simple = "< a < b < c < d" ;
RuleBasedCollator col
= new RuleBasedCollator(simple);
col.setDecomposition(
Collator.CANONICAL_DECOMPOSITION);
int mode = col.getDecomposition();
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
Reference: https://docs.oracle.com/javase/9/docs/api/java/text/Collator.html#setDecomposition-int-
Last Updated :
27 Dec, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...