Compartilhar via


Collator Class

Definition

The Collator class performs locale-sensitive String comparison.

[Android.Runtime.Register("java/text/Collator", DoNotGenerateAcw=true)]
public abstract class Collator : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.Lang.ICloneable, Java.Util.IComparator
[<Android.Runtime.Register("java/text/Collator", DoNotGenerateAcw=true)>]
type Collator = class
    inherit Object
    interface ICloneable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface IComparator
Inheritance
Collator
Derived
Attributes
Implements

Remarks

The Collator class performs locale-sensitive String comparison. You use this class to build searching and sorting routines for natural language text.

Collator is an abstract base class. Subclasses implement specific collation strategies. One subclass, RuleBasedCollator, is currently provided with the Java Platform and is applicable to a wide set of languages. Other subclasses may be created to handle more specialized needs.

Like other locale-sensitive classes, you can use the static factory method, getInstance, to obtain the appropriate Collator object for a given locale. You will only need to look at the subclasses of Collator if you need to understand the details of a particular collation strategy or if you need to modify that strategy.

The following example shows how to compare two strings using the Collator for the default locale. <blockquote>

{@code
            // Compare two strings in the default locale
            Collator myCollator = Collator.getInstance();
            if( myCollator.compare("abc", "ABC") < 0 )
                System.out.println("abc is less than ABC");
            else
                System.out.println("abc is greater than or equal to ABC");
            }

</blockquote>

You can set a Collator's <em>strength</em> property to determine the level of difference considered significant in comparisons. Four strengths are provided: PRIMARY, SECONDARY, TERTIARY, and IDENTICAL. The exact assignment of strengths to language features is locale dependent. For example, in Czech, "e" and "f" are considered primary differences, while "e" and "&#283;" are secondary differences, "e" and "E" are tertiary differences and "e" and "e" are identical. The following shows how both case and accents could be ignored for US English. <blockquote>

//Get the Collator for US English and set its strength to PRIMARY
            Collator usCollator = Collator.getInstance(Locale.US);
            usCollator.setStrength(Collator.PRIMARY);
            if( usCollator.compare("abc", "ABC") == 0 ) {
                System.out.println("Strings are equivalent");
            }

</blockquote>

For comparing Strings exactly once, the compare method provides the best performance. When sorting a list of Strings however, it is generally necessary to compare each String multiple times. In this case, CollationKeys provide better performance. The CollationKey class converts a String to a series of bits that can be compared bitwise against other CollationKeys. A CollationKey is created by a Collator object for a given String. <br> <strong>Note:</strong> CollationKeys from different Collators can not be compared. See the class description for CollationKey for an example using CollationKeys.

Added in 1.1.

Java documentation for java.text.Collator.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

Collator()

Default constructor.

Collator(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Fields

CanonicalDecomposition

Decomposition mode value.

FullDecomposition

Decomposition mode value.

Identical

Collator strength value.

NoDecomposition

Decomposition mode value.

Primary

Collator strength value.

Secondary

Collator strength value.

Tertiary

Collator strength value.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Decomposition

Get the decomposition mode of this Collator. -or- Set the decomposition mode of this Collator.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
Instance

Gets the Collator for the current default locale.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
Strength

Returns this Collator's strength property. -or- Sets this Collator's strength property.

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Clone()

Returns a new collator with the same decomposition mode and strength value as this collator.

Compare(Object, Object)

Compares its two arguments for order.

Compare(String, String)

Compares the source string to the target string according to the collation rules for this Collator.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
Equals(String, String)

Convenience method for comparing the equality of two strings based on this Collator's collation rules.

GetAvailableLocales()

Returns an array of all locales for which the getInstance methods of this class can return localized instances.

GetCollationKey(String)

Transforms the String into a series of bits that can be compared bitwise to other CollationKeys.

GetHashCode()

Generates the hash code for this Collator.

GetInstance(Locale)

Gets the Collator for the desired locale.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IComparator.Compare(Object, Object)
IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to