[{TIME21=0, TIME22=2, TIME23=0, TIME12=0, TIME13=1, LOAN_AMT=500, TIME10=0, TIME20=0, TIME11=1, TIME17=0, TIME9=2, TIME16=0, TIME15=0, TIME14=1, TIME5=0, REG_DT=20170517, TIME6=0, TIME19=0, TIME7=0, TIME18=1, TIME8=4, TIME1=0, TIME2=0, TIME3=0, TIME4=0, TIME0=0}, {TIME21=3, TIME22=2, TIME23=3, TIME12=6, TIME13=7, LOAN_AMT=1000, TIME10=8, TIME20=2, TIME11=6, TIME17=6, TIME9=7, TIME16=2, TIME15=7, TIME14=5, TIME5=0, REG_DT=20170517, TIME6=1, TIME19=1, TIME7=3, TIME18=1, TIME8=5, TIME1=0, TIME2=1, TIME3=0, TIME4=0, TIME0=3}]
這是一個列表,表單是List>,我想排序讓它顯示像TIME1,TIME2 ......,我應該怎麼做,以及這樣,這類型TIME1是BigDecimal的,這是我的代碼,但它不是劑量工作我如何對它進行排序
for (Map<String, Object> dataMap : chartData) {
List<Object> objs = new ArrayList<Object>();
for (final Map.Entry<String, Object> entry : dataMap.entrySet()) {
Collections.sort(chartData,new Comparator<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
BigDecimal s1 = (BigDecimal) o1.get(entry.getKey());
BigDecimal s2 = (BigDecimal) o2.get(entry.getKey());
int result = s1.compareTo(s2);
if (result < 0) {
System.out.println("a < b");
return 1;
}else {
System.out.println("a>b");
return -1;
}
}
});
}
}
「不起作用」不起作用問題描述。 – EJoshuaS
你在排序什麼?你說你想要TIME1,TIME2,但是你開始使用'BigDecimal'?那麼LOAN_AMT和其他的東西呢?如果您正在嘗試對TIME1,TIME2進行排序,您還需要將其分開,否則您將有TIME1,TIME10,TIME2,TIME20,TIME3,... – KevinO
LOAN_AMT可以忽略 – Aaron