首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

对hash地图按值排序如何做

2012-11-12 
对hashmap按值排序怎么做?问题:对hashmap按值排序怎么做??方法1、??public static void main(String[] args

对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));
??}
?}

热点排行