码迷,mamicode.com
首页 > 编程语言 > 详细

对map进行排序

时间:2017-04-24 22:54:42      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:treemap   out   bsp   ext   turn   aaa   iterator   put   keyset   

public class TreeMapTest {
    public static void main(String[] args) {
        Map<String, String> map = new TreeMap<String, String>(
                new Comparator<String>() {
                    public int compare(String obj1, String obj2) {
                        // 降序排序
                        return obj2.compareTo(obj1);
                    }
                });
        map.put("c", "ccccc");
        map.put("a", "aaaaa");
        map.put("b", "bbbbb");
        map.put("d", "ddddd");

        Set<String> keySet = map.keySet();
        Iterator<String> iter = keySet.iterator();
        while (iter.hasNext()) {
            String key = iter.next();
            System.out.println(key + ":" + map.get(key));
        }
    }
}

对map进行排序

标签:treemap   out   bsp   ext   turn   aaa   iterator   put   keyset   

原文地址:http://www.cnblogs.com/kongxc/p/6759177.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!