用TreeMap对key排序

//按年份,取出最近10项
        List<StatisticalData> projectYear = statisticalInfo.getProjectYear();
        Map<String,String> treeMap = new TreeMap<String,String>();
        Map<String,String> hashMap = new HashMap<String,String>();
        for (StatisticalData statisticalData : projectYear) {
            treeMap.put(statisticalData.getName(),statisticalData.getValue());
            hashMap.put(statisticalData.getName(),statisticalData.getValue());
        } 
        
        //排序treeMap:{2010-03=3, 2010-04=1, 2010-05=3, 2010-06=1, 2010-08=1, 2010-09=2, 2010-11=1, 2010-12=2, 2011-01=4, 2011-03=2, 2011-04=7, 2011-05=1, 2011-07=1, 2011-10=3, 2011-11=1, 2011-12=3, 2012-02=1, 2012-03=2, 2012-04=1, 2012-05=1, 2012-07=3, 2012-08=6, 2012-09=2, 2012-10=1, 2012-12=2, 2013-01=1, 2013-03=6, 2013-04=1, 2013-05=6, 2013-06=5, 2013-07=2}


        //无序hashMap:{2012-02=1, 2012-03=2, 2012-04=1, 2012-05=1, 2012-07=3, 2012-08=6, 2012-09=2, 2010-11=1, 2010-12=2, 2011-12=3, 2011-10=3, 2011-11=1, 2013-01=1, 2011-07=1, 2011-05=1, 2011-04=7, 2011-03=2, 2011-01=4, 2010-06=1, 2010-05=3, 2010-04=1, 2010-03=3, 2012-12=2, 2013-07=2, 2012-10=1, 2013-03=6, 2013-04=1, 2013-05=6, 2010-09=2, 2010-08=1, 2013-06=5}
         

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值