我使用的是比較通過IRC用戶列表和人物,如[
和_
先@
進行排序。我如何防止這種情況?我希望以這些角色開頭的用戶成爲普通用戶。現在看起來比較器:Java集合的排序W /比較細節
public class UserListSorter implements Comparator<String> {
// Get the Collator for the current locale.
private Collator collator = Collator.getInstance();
@Override // The comparator that implements the abovementioned.
public int compare(String o1, String o2) { // Compare these users.
int compare = compareString(o1.substring(0, 2), o2.substring(0, 2)); // Get the user group of the users (@,+,())
if (compare == 0) { // If both are in the same group, sort by
return compareString(o1, o2); // their name only.
}
return compare; // Else, return a positive value stating
} // that @ and + holds a higher value than().
private int compareString(String o1, String o2) { // Compares the users alphabetically, ignoring small
return collator.compare(o1, o2); // and capital letters. Used as a basis for sorting algo.
}
}
謝謝。
「我該如何預防?」但你期望的行爲是什麼?把用'@'開頭的用戶名放在其他位置之前? – Viruzzo
是的,這是IRC用戶列表的正常行爲。 – dueland
嗯......這與揮杆有什麼關係? – kleopatra