展开全部
java中对集合排序,可以62616964757a686964616fe78988e69d8331333337623434使用Collections.sort来进行排序,可以对中文、字母、数字进行排序,当比较的是对象时候,让该类实现comparable接口,示例如下:Collections.sort(dataMap, new Comparator>() {
//排序接口实现方法
@Override
public int compare(Map lhs, Map rhs) {
switch (whichsort) {
case System_OpenPosition_Sort_Currency:
String d2 = ((String) rhs.get(Instrument));
String d1 = (String) lhs.get(Instrument);
if (d2 != null && d1 != null) {
int flag = d1.compareTo(d2);
if (flag == 0) {
Double d3 = ((Double) rhs.get(OpenPrice));
Double d4 = (Double) lhs.get(OpenPrice);
if (d3 != null && d4 != null) {
int flag2 = d4.compareTo(d3);
if (flag2 == 0) {
String d5 = ((String) rhs.get(BuySell));
String d6 = (String) lhs.get(BuySell);//文字排序
if (d5 != null && d6 != null) {
return d6.compareTo(d5);//返回一个int类型,用来判断是否大于、小于还是等于
}
}
return d4.compareTo(d3);
}
} else {
return flag;
}
// return d1.compareTo(d2);
}