## Collections.sort 是稳定排序吗？结果

public class Main {

public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
while (sin.hasNext()) {
int n = Integer.parseInt(sin.nextLine());
int flag = Integer.parseInt(sin.nextLine());
Map<String, Integer> map = new HashMap<>(n);
for (int i = 0; i < n; i++) {
String str = sin.nextLine();
String[] strArray = str.split("\\s+");
map.put(strArray[0], Integer.parseInt(strArray[1]));
}
List<Map.Entry<String, Integer>> list = new ArrayList<>(map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {

@Override
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
return o1.getValue() - o2.getValue();
}
});
System.out.println(list);
if (flag == 1) {
for (int i = 0; i < list.size(); i++) {
Map.Entry<String, Integer> e = list.get(i);
System.out.println(e.getKey() + " " + e.getValue());
}
} else {
for (int i = list.size() - 1; i >= 0; i--) {
Map.Entry<String, Integer> e = list.get(i);
System.out.println(e.getKey() + " " + e.getValue());
}
}
}
}
}

Console：

3
1
Tom 88
Jack 88
Jim 88
[Jim=88, Tom=88, Jack=88]
Jim 88
Tom 88
Jack 88

0

0

0