论坛首页 入门技术论坛

Java中Map的排序

浏览 11630 次
该帖已经被评为新手帖
作者 正文
   发表时间:2011-06-03  
 List arrayList = new ArrayList(map.entrySet());  
//注意构造函数      
            //排序前  
        for(Iterator it = arrayList.iterator();it.hasNext();){  
            Map.Entry entry = (Map.Entry)it.next();  
            System.out.print(entry.getKey()+":"+entry.getValue()+"  ");  
        }  
      [color=red]  Collections.sort(arrayList, new TariffComparator.TariffMapComparator());  [/color]
        System.out.println();  
        //排序后  
        for(Iterator it = arrayList.iterator();it.hasNext();){  
            Map.Entry entry = (Map.Entry)it.next();  
            System.out.println(entry.getKey()+":"+entry.getValue());  
        }  


哥们,你没有对Map排序呀,你就对List排个序,这个HashMap的key值该怎样还是怎样(无序的),看来上iteye以后只能看扯皮,口水和侃工资了。
0 请登录后投票
   发表时间:2011-06-03  
Morgan0916 写道
jackra 写道
传说
SET是排序的
MAP是哈希的
LIST是序列的


无语!!!

这样做东西,能用?以后各位考察初程要改改习惯了,别老ssh,啥啥框架的,外包害死人
0 请登录后投票
   发表时间:2011-06-03  
wuzaizhong283 写道
Morgan0916 写道
jackra 写道
传说
SET是排序的
MAP是哈希的
LIST是序列的


无语!!!

这样做东西,能用?以后各位考察初程要改改习惯了,别老ssh,啥啥框架的,外包害死人


set 是无序集合的说。
0 请登录后投票
   发表时间:2011-06-06  
jackra 写道
传说
SET是排序的
MAP是哈希的
LIST是序列的

传说哥,太强悍了,哈哈
0 请登录后投票
   发表时间:2011-06-07  
jackra 写道
传说
SET是排序的
MAP是哈希的
LIST是序列的


set是无序的
map是key/value映射
list是有序的
0 请登录后投票
   发表时间:2011-07-11  
003 写道
TreeMap有构造方法public TreeMap(Comparator<? super K> comparator),可以直接实现排序


+1 并且支持中文排序。
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics