搜尋

首頁  >  問答  >  主體

java 排序的問題

[{TIME21=0, TIME22=2, TIME23=0, TIME12=0, TIME13=1, LOAN_AMT=500, TIME10=0, TIME20=0, TIME11=1, TIME17=0, TIME17=0, TIME96 =0, TIME15=0, TIME14=1, TIME5=0, REG_DT=20170517, TIME6=0, TIME19=0, TIME7=0, TIME18=1, TIME8=4, TIME1=0, TIME2=0, TI , TIME4=0, TIME0=0}, {TIME21=3, TIME22=2, TIME23=3, TIME12=6, TIME13=7, LOAN_AMT=1000, TIME10=8, TIME20=2, TIME17,6, TIME , TIME9=7, TIME16=2, TIME15=7, TIME14=5, TIME5=0, REG_DT=20170517, TIME6=1, TIME19=1, TIME7=3, TIME18=1, TIME8=5, TIME =1, TIME3=0, TIME4=0, TIME0=3}]

這是一個形式為List<Map<String,Object>> 格式的list,裡面是map,我想經過排序後讓其按照TIME0,TIME1,TIME2.....TIME23的形式排序,該怎麼排序呢?而且類似 TIME1 這種的型別是BigDecimal。裡面的LOAN_AMT和REG_DT不用管,我只是用循環得到TIMExx這些資訊

为情所困为情所困2768 天前551

全部回覆(1)我來回復

  • 漂亮男人

    漂亮男人2017-05-27 17:42:50

    其實,你只需要把List<Map<String,Object>>改成List<TreeMap<String,Object>>就可以了.....
    TreeMap是按照Kay進行排序的。

    TreeMap<String,Object> map = new TreeMap<>();
    map.put("TIME0","TIME0");
    map.put("TIME22","TIME22");
    map.put("TIME15","TIME15");
    map.put("TIME11","TIME11");
    map.put("TIME19","TIME19");
    map.put("TIME1","TIME1");
    
    System.out.println(map); // {TIME0=TIME0, TIME1=TIME1, TIME11=TIME11, TIME15=TIME15, TIME19=TIME19, TIME22=TIME22}
    

    回覆
    0
  • 取消回覆