java.text.Collator
java.lang.Object
java.text.RuleBasedCollator
java.lang.Cloneable, java.io.Serializable
New as of JDK 1.1
The Collator class compares strings in a manner that is appropriate for a particular locale. Although Collator is an abstract class, the getInstance() factory methods can be used to get a usable instance of a Collator subclass that implements a particular collation strategy. One subclass, RuleBasedCollator, is provided as part of the JDK.
A Collator object has a strength property that controls the level of difference that is considered significant for comparison purposes. The Collator class provides four strength values: PRIMARY, SECONDARY, TERTIARY, and IDENTICAL. Although the interpretation of these strengths is locale-dependent, they generally have the following meanings:
The comparison considers letter differences, but ignores case and diacriticals.
The comparison considers letter differences and diacriticals, but ignores case.
The comparison considers letter differences, case, and diacriticals.
The comparison considers all differences.
The default comparison strength is TERTIARY.
If you only need to compare two String objects once, the compare() method of the Collator class provides the best performance. However, if you need to compare the same String objects multiple times, such as when you are sorting, you should use CollationKey objects instead. A CollationKey object contains a String that has been converted into a series of bits that can be compared in a bitwise fashion against other CollationKey objects. You use a Collator object to create a CollationKey for a given String.
public abstract class java.text.Collator extends java.lang.Object implements java.io.Serializable, java.lang.Cloneable { // Constants public static final int CANONICAL_DECOMPOSITION; public static final int FULL_DECOMPOSITION; public static final int IDENTICAL; public static final int NO_DECOMPOSITION; public static final int PRIMARY; public static final int SECONDARY; public static final int TERTIARY; // Constructors protected Collator(); // Class Methods public static synchronized Locale[] getAvailableLocales(); public static synchronized Collator getInstance(); public static synchronized Collator getInstance(Locale desiredLocale); // Instance Methods public Object clone(); public abstract int compare(String source, String target); public boolean equals(Object that); public boolean equals(String source, String target); public abstract CollationKey getCollationKey(String source); public synchronized int getDecomposition(); public synchronized int getStrength(); public abstract synchronized int hashCode(); public synchronized void setDecomposition(int decompositionMode); public synchronized void setStrength(int newStrength); }
A decomposition constant that specifies that Unicode 2.0 characters which are canonical variants are decomposed for collation. This is the default decomposition setting.
A decomposition constant that specifies that Unicode 2.0 canonical variants and compatibility variants are decomposed for collation. This is the most complete decomposition setting, and thus the slowest setting.
A strength constant that specifies that all differences are considered significant for comparison purposes.
A decomposition setting that specifies that no Unicode characters are decomposed for collation. This is the least complete decomposition setting, and thus the fastest setting. It only works correctly for languages that do not use diacriticals.
A strength constant that specifies that only primary differences are considered significant for comparison purposes. Primary differences are typically letter differences.
A strength constant that specifies that only secondary differences and above are considered significant for comparison purposes. Secondary differences are typically differences in diacriticals, or accents.
A strength constant that specifies that only tertiary differences and above are considered significant for comparison purposes. Tertiary differences are typically differences in case. This is the default strength setting.
This constructor creates a Collator with the default strength of TERTIARY and default decomposition mode of CANONICAL_DECOMPOSITION.
An array of Locale objects.
This method returns an array of the Locale objects for which this class can create Collator objects.
A Collator appropriate for the default Locale.
This method creates a Collator that compares strings in the default Locale.
public static synchronized Collator getInstance( Locale desiredLocale)
The Locale to use.
A Collator appropriate for the given Locale.
This method creates a Collator that compares strings in the given Locale.
A copy of this Collator.
Object.clone()
This method creates a copy of this Collator and returns it.
The source string.
The target string.
-1 if source is less than target, 0 if the strings are equal, or 1 if source is greater than target.
This method compares the given strings according to the collation rules for this Collator and returns a value that indicates their relationship. If either of the strings are compared more than once, a CollationKey should be used instead.
The object to be compared with this object.
true if the objects are equal; false if they are not.
Object.equals()
This method returns true if obj is an instance of Collator and is equivalent to this Collator.
The source string.
The target string.
true if the given strings are equal; false otherwise.
This method compares the given strings for equality using the collation rules for this Collator. Note that this method applies locale-specific rules and is thus not the same as String.equals().
The string to use when generating the CollationKey.
A CollationKey for the given string.
This method generates a CollationKey for the given string. The returned object can be compared with other CollationKey objects using CollationKey.compareTo(). This comparison is faster than using Collator.compare(), so if the same string is used for many comparisons, you should use CollationKey objects.
The decomposition mode for this Collator.
This method returns the current decomposition mode for this Collator. The decomposition mode specifies how composed Unicode characters are handled during collation. You can adjust the decomposition mode to choose between faster and more complete collation. The returned value is one of the following values: NO_DECOMPOSITION, CANONICAL_DECOMPOSITION, or FULL_DECOMPOSITION.
The strength setting for this Collator.
This method returns the current strength setting for this Collator. The strength specifies the minimum level of difference that is considered significant during collation. The returned value is one of the following values: PRIMARY, SECONDARY, TERTIARY, or IDENTICAL.
A hashcode for this object.
Object.hashCode()
This method returns a hashcode for this Collator.
The decomposition mode: NO_DECOMPOSITION, CANONICAL_DECOMPOSITION, or FULL_DECOMPOSITION.
This method sets the decomposition mode for this Collator. The decomposition mode specifies how composed Unicode characters are handled during collation. You can adjust the decomposition mode to choose between faster and more complete collation.
The new strength setting: PRIMARY, SECONDARY, TERTIARY, or IDENTICAL.
This method sets the strength of this Collator. The strength specifies the minimum level of difference that is considered significant during collation.
Method | Inherited From | Method | Inherited From |
---|---|---|---|
finalize() |
Object |
getClass() |
Object |
notify() |
Object |
notifyAll() |
Object |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
CollationKey, Locale, RuleBasedCollator, String