我有一个集合排序收藏...我写的代码,用我自己的比较器来排序值 我比较代码在Java字符串元素
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
比较是字典而不是数字,这是你的问题。 – 2010-09-03 10:43:40
我该如何解决这个问题? – Kandha 2010-09-03 10:44:31