IT. Expert System.

Android Reference



Class CollationKey

  • All Implemented Interfaces:

    public abstract class CollationKey
    extends Object
    implements Comparable<CollationKey>
    Represents a string under the rules of a specific Collator object. Comparing two CollationKey instances returns the relative order of the strings they represent.

    Since the rule set of collators can differ, the sort orders of the same string under two different Collator instances might differ. Hence comparing collation keys generated from different Collator instances can give incorrect results.

    Both the method CollationKey.compareTo(CollationKey) and the method, String) compares two strings and returns their relative order. The performance characteristics of these two approaches can differ.

    During the construction of a CollationKey, the entire source string is examined and processed into a series of bits terminated by a null, that are stored in the CollationKey. When CollationKey.compareTo(CollationKey) executes, it performs bitwise comparison on the bit sequences. This can incur startup cost when creating the CollationKey, but once the key is created, binary comparisons are fast. This approach is recommended when the same strings are to be compared over and over again.

    On the other hand, implementations of, String) can examine and process the strings only until the first characters differ in order. This approach is recommended if the strings are to be compared only once.

    The following example shows how collation keys can be used to sort a list of strings:

     // Create an array of CollationKeys for the Strings to be sorted.
     Collator myCollator = Collator.getInstance();
     CollationKey[] keys = new CollationKey[3];
     keys[0] = myCollator.getCollationKey("Tom");
     keys[1] = myCollator.getCollationKey("Dick");
     keys[2] = myCollator.getCollationKey("Harry");
    // Inside body of sort routine, compare keys this way if( keys[i].compareTo( keys[j] ) > 0 ) // swap keys[i] and keys[j]
    // Finally, when we've returned from sort. System.out.println(keys[0].getSourceString()); System.out.println(keys[1].getSourceString()); System.out.println(keys[2].getSourceString());
    See Also:
    Collator, RuleBasedCollator
    • Constructor Detail

      • CollationKey

        protected CollationKey(String source)
    • Method Detail

      • compareTo

        public abstract int compareTo(CollationKey value)
        Compares this collation key to the given collation key.
        Specified by:
        compareTo in interface Comparable<CollationKey>
        value - the other collation key.
        a negative value if this key is less than value, 0 if they are equal, and a positive value if this key is greater.
      • getSourceString

        public String getSourceString()
        Returns the string from which this collation key was created.
        the source string of this collation key.
      • toByteArray

        public abstract byte[] toByteArray()
        Returns this collation key as a byte array.
        an array of bytes.


Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)





Java Script








Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 114 / 158767486. Delta: 0.07980 с