<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<!--NewPage-->
<html>
<head>
<!-- Generated by javadoc on Wed Jul 28 01:21:15 GMT 1999 -->
<title>
  Class java.text.CollationKey
</title>
</head>
<body>
<a name="_top_"></a>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.text.html">This Package</a>  <a href="java.text.CollationElementIterator.html#_top_">Previous</a>  <a href="java.text.Collator.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
<hr>
<h1>
  Class java.text.CollationKey
</h1>
<pre>
<a href="java.lang.Object.html#_top_">java.lang.Object</a>
   |
   +----java.text.CollationKey
</pre>
<hr>
<dl>
  <dt> public final class <b>CollationKey</b>
  <dt> extends <a href="java.lang.Object.html#_top_">Object</a>
</dl>
A <code>CollationKey</code> represents a <code>String</code> under the
 rules of a specific <code>Collator</code> object. Comparing two
 <code>CollationKey</code>s returns the relative order of the
 <code>String</code>s they represent. Using <code>CollationKey</code>s
 to compare <code>String</code>s is generally faster than using
 <code>Collator.compare</code>. Thus, when the <code>String</code>s
 must be compared multiple times, for example when sorting a list
 of <code>String</code>s. It's more efficient to use <code>CollationKey</code>s.
 <p>
 You can not create <code>CollationKey</code>s directly. Rather,
 generate them by calling <code>Collator.getCollationKey</code>.
 You can only compare <code>CollationKey</code>s generated from
 the same <code>Collator</code> object.
 <p>
 Generating a <code>CollationKey</code> for a <code>String</code>
 involves examining the entire <code>String</code>
 and converting it to series of bits that can be compared bitwise. This
 allows fast comparisons once the keys are generated. The cost of generating
 keys is recouped in faster comparisons when <code>String</code>s need
 to be compared many times. On the other hand, the result of a comparison
 is often determined by the first couple of characters of each <code>String</code>.
 <code>Collator.compare</code> examines only as many characters as it needs which
 allows it to be faster when doing single comparisons.
 <p>
 The following example shows how <code>CollationKey</code>s might be used
 to sort a list of <code>String</code>s.
 <blockquote>
 <pre>
 // 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");
 sort( keys );
 <nsbr>
 //...
 <nsbr>
 // Inside body of sort routine, compare keys this way
 if( keys[i].compareTo( keys[j] ) > 0 )
    // swap keys[i] and keys[j]
 <nsbr>
 //...
 <nsbr>
 // 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() );
 </pre>
 </blockquote>
<p>
<dl>
    <dt> <b>See Also:</b>
    <dd> <a href="java.text.Collator.html#_top_">Collator</a>, <a href="java.text.RuleBasedCollator.html#_top_">RuleBasedCollator</a>
</dl>
<hr>
<a name="index"></a>
<h2>
  <img src="images/method-index.gif" width=207 height=38 alt="Method Index">
</h2>
<dl>
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#compareTo(java.text.CollationKey)"><b>compareTo</b></a>(CollationKey)
  <dd>  Compare this CollationKey to the target CollationKey.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#equals(java.lang.Object)"><b>equals</b></a>(Object)
  <dd>  Compare this CollationKey and the target CollationKey for equality.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getSourceString()"><b>getSourceString</b></a>()
  <dd>  Returns the String that this CollationKey represents.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#hashCode()"><b>hashCode</b></a>()
  <dd>  Creates a hash code for this CollationKey.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#toByteArray()"><b>toByteArray</b></a>()
  <dd>  Converts the CollationKey to a sequence of bits.
</dl>
<a name="methods"></a>
<h2>
  <img src="images/methods.gif" width=151 height=38 alt="Methods">
</h2>
<a name="compareTo(java.text.CollationKey)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="compareTo"><b>compareTo</b></a>
<pre>
 public int compareTo(<a href="#_top_">CollationKey</a> target)
</pre>
<dl>
  <dd> Compare this CollationKey to the target CollationKey. The collation rules of the
 Collator object which created these keys are applied. <strong>Note:</strong>
 CollationKeys created by different Collators can not be compared.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> target - target CollationKey
    <dt> <b>Returns:</b>
    <dd> Returns an integer value. Value is less than zero if this is less
 than target, value is zero if this and target are equal and value is greater than
 zero if this is greater than target.
    <dt> <b>See Also:</b>
    <dd> <a href="java.text.Collator.html#compare">compare</a>
  </dl></dd>
</dl>
<a name="equals(java.lang.Object)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="equals"><b>equals</b></a>
<pre>
 public boolean equals(<a href="java.lang.Object.html#_top_">Object</a> target)
</pre>
<dl>
  <dd> Compare this CollationKey and the target CollationKey for equality.
 The collation rules of the Collator object which created these keys are applied.
 <strong>Note:</strong> CollationKeys created by different Collators can not be
 compared.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> target - the CollationKey to compare to.
    <dt> <b>Returns:</b>
    <dd> Returns true if two objects are equal, false otherwise.
    <dt> <b>Overrides:</b>
    <dd> <a href="java.lang.Object.html#equals(java.lang.Object)">equals</a> in class <a href="java.lang.Object.html#_top_">Object</a>
  </dl></dd>
</dl>
<a name="hashCode()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="hashCode"><b>hashCode</b></a>
<pre>
 public int hashCode()
</pre>
<dl>
  <dd> Creates a hash code for this CollationKey. The hash value is calculated on the
 key itself, not the String from which the key was created.  Thus
 if x and y are CollationKeys, then x.hashCode(x) == y.hashCode() if
 x.equals(y) is true.  This allows language-sensitive comparison in a hash table.
 See the CollatinKey class description for an example.
<p>
  <dd><dl>
    <dt> <b>Returns:</b>
    <dd> the hash value based on the string's collation order.
    <dt> <b>Overrides:</b>
    <dd> <a href="java.lang.Object.html#hashCode()">hashCode</a> in class <a href="java.lang.Object.html#_top_">Object</a>
  </dl></dd>
</dl>
<a name="getSourceString()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getSourceString"><b>getSourceString</b></a>
<pre>
 public <a href="java.lang.String.html#_top_">String</a> getSourceString()
</pre>
<dl>
  <dd> Returns the String that this CollationKey represents.
<p>
</dl>
<a name="toByteArray()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="toByteArray"><b>toByteArray</b></a>
<pre>
 public byte[] toByteArray()
</pre>
<dl>
  <dd> Converts the CollationKey to a sequence of bits. If two CollationKeys
 could be legitimately compared, then one could compare the byte arrays
 for each of those keys to obtain the same result.  Byte arrays are
 organized most significant byte first.
<p>
</dl>
<hr>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.text.html">This Package</a>  <a href="java.text.CollationElementIterator.html#_top_">Previous</a>  <a href="java.text.Collator.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
</body>
</html>
