1. 程式人生 > >java集合排序的使用

java集合排序的使用

java集合排序

		List<String> lastEventCauselist = new ArrayList<String>();
		List<String> lastNumlist = new ArrayList<String>();
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        for(int i=0;i<Numlist.size();i++) {
        	map.put(eventCauselist.get(i), Integer.valueOf(Numlist.get(i)));
        }
		
        List<Map.Entry<String,Integer>> list = new ArrayList<Map.Entry<String,Integer>>(map.entrySet());
        Collections.sort(list,new Comparator<Map.Entry<String,Integer>>() {
            //升序排序
            public int compare(Entry<String, Integer> o1,
                    Entry<String, Integer> o2) {
                return o1.getValue().compareTo(o2.getValue());
            }

        });
        
        for(Map.Entry<String,Integer> mapping:list){ 
        	lastEventCauselist.add(mapping.getKey());
        	lastNumlist.add(String.valueOf(mapping.getValue()));
       } 
        
		
		maps.put("eventCauselist", eventCauselist);
		maps.put("Numlist", Numlist);