【发布时间】:2011-07-16 21:08:08
【问题描述】:
我有一个基于运动的不同类型球员的数组列表。我需要按姓氏对arrayList 中的玩家列表进行排序才能开始。如果 2 名玩家的姓氏相同,则需要按名字对这 2 名玩家进行排序。 示例:格式化姓氏名
Williams Robert
Phillips Warren
Doe John
Phillips Mark
输出应该是
Doe John
Phillips Mark
Phillips Warren
Williams Robert
我现在只按第一个或最后一个排序。我的代码中的最后一个 atm 有它。
public static void sortPlayers(ArrayList playerList) {
for (int i = 0; i < playerList.size(); i++) {
for (int j = 0; j < playerList.size(); j++) {
Collections.sort(playerList, new Comparator() {
public int compare(Object o1, Object o2) {
PlayerStats p1 = (PlayerStats) o1;
PlayerStats p2 = (PlayerStats) o2;
return p1.getPlayerLastName().compareToIgnoreCase(p2.getPlayerLastName());
}
});
}
}
}
【问题讨论】:
标签: java