Where Am I? Class Hierarchy (JDK) All Classes (JDK) All Fields and Methods (JDK)

Class java.text.RuleBasedCollator

java.lang.Object
   |
   +----java.text.Collator
           |
           +----java.text.RuleBasedCollator

public class RuleBasedCollator
extends Collator

The RuleBasedCollator class is a concrete subclass of Collator that provides a simple, data-driven, table collator. With this class you can create a customized table-based Collator. RuleBasedCollator maps characters to sort keys.

RuleBasedCollator has the following restrictions for efficiency (other subclasses may be used for more complex languages) :

  1. If a French secondary ordering is specified it applies to the whole collator object.
  2. All non-mentioned Unicode characters are at the end of the collation order.
  3. Private use characters are treated as identical. The private use area in Unicode is 0xE800-0xF8FF.

The collation table is composed of a list of collation rules, where each rule is of three forms:

    
     
     
 
The following demonstrates how to create your own collation rules:

This sounds more complicated than it is in practice. For example, the following are equivalent ways of expressing the same thing:

 a 
 
Notice that the order is important, as the subsequent item goes immediately after the text-argument. The following are not equivalent:
 a 
 
Either the text-argument must already be present in the sequence, or some initial substring of the text-argument must be present. (e.g. "a Ignorable Characters

For ignorable characters, the first rule must start with a relation (the examples we have used above are really fragments; "a Normalization and Accents

The Collator object automatically normalizes text internally to separate accents from base characters where possible. This is done both when processing the rules, and when comparing two strings. Collator also uses the Unicode canonical mapping to ensure that combining sequences are sorted properly.

Errors

The following are errors: