读书人

对hash地图按值排序如何做

发布时间: 2012-11-12 12:31:58 作者: rapoo

对hashmap按值排序怎么做?

问题:对hashmap按值排序怎么做?

?

方法1、

?

?public static void main(String[] args){
??Map map=new HashMap();
??map.put("d", 761);
??map.put("g", 7);
??map.put("a", 7612);
??map.put("c", 34);
??
??int value=0;
???? String maxKey = null;
???? List list=new ArrayList();
????
??Iterator ite=map.entrySet().iterator();
??while(ite.hasNext()){
?????????? Map.Entry entry =(Map.Entry)ite.next();
??????????? value = Integer.parseInt(entry.getValue().toString());
??????????? list.add(entry.getValue());
??????????? Collections.sort(list);
???? }
???? ?for(int i=0;i<list.size();i++){
???System.out.println(list.get(i));
??}
?}

读书人网 >编程

热点推荐