【发布时间】:2010-09-03 10:41:35
【问题描述】:
我有一个集合...我编写了代码来使用我自己的比较器对值进行排序 我的比较器代码是
private static class MatchComparator implements Comparator<xmlparse> {
@Override
public int compare(xmlparse object1, xmlparse object2) {
String match1 = object1.getMatchId();
String match2 = object2.getMatchId();
return match1.compareTo(match2);
}
}
我会打电话给Collections.sort(list,new MatchComparator());
一切都很好,但我的问题是当我打印时排序列表是错误的......
列表输入
Match19
Match7
Match12
Match46
Match32
排序列表的输出
Match12
Match19
Match32
Match46
Match7
我的预期输出是
Match7
Match12
Match19
Match32
Match46
【问题讨论】:
-
比较是字典而不是数字,这是你的问题。
-
我该如何解决这个问题?
标签: java collections