public abstract class CollationKey extends Object implements Comparable<CollationKey>
CollationKey
代表一个特定的对象
String
Collator
规则下。比较两
CollationKey
s返回他们所代表的
String
s相对阶。使用
CollationKey
s比较
String
s通常比使用
Collator.compare
更快。因此,当
String
s必须比较多的时候,例如当排序
String
s。使用
CollationKey
s更有效。
你不能创造CollationKey
s直接。相反,他们通过电话Collator.getCollationKey
生成。你可以比较同一Collator
物体产生CollationKey
s。
生成一String
CollationKey
审查涉及整个String
并将其转换成比特位序列可以比较。这允许快速的比较,一旦产生的密钥。生成密钥的成本收回更快String
s比较时需要多次比较。另一方面,比较的结果往往是由各String
人物第一夫妇决定。Collator.compare
仅考察的许多人物,需要可以更快的做单比较时。
下面的示例演示如何CollationKey
s可以用来String
s排序列表。
// 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); //... // 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());
Collator
,
RuleBasedCollator
Modifier | Constructor and Description |
---|---|
protected |
CollationKey(String source)
collationkey构造函数。
|
Modifier and Type | Method and Description |
---|---|
abstract int |
compareTo(CollationKey target)
比较CollationKey的目标CollationKey。
|
String |
getSourceString()
返回CollationKey所代表的字符串。
|
abstract byte[] |
toByteArray()
将collationkey一位序列。
|
protected CollationKey(String source)
source
-源字符串
NullPointerException
-如果
source
是空的
public abstract int compareTo(CollationKey target)
compareTo
接口
Comparable<CollationKey>
target
目标CollationKey
Collator.compare(java.lang.String, java.lang.String)
public String getSourceString()
public abstract byte[] toByteArray()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.