- public class map {
- public static void main(String[] args) {
- getMap();
- }
-
- static void getMap(){
- HashMap<String,Integer> map = new HashMap<String,Integer>();
- map.put("a",1);
- map.put("b",9);
- map.put("c",7);
- map.put("d",1);
- map.put("e",2);
- map.put("f",5);
- map.put("g",4);
-
- Set<Entry<String,Integer>> set = map.entrySet();
- ArrayList<Entry<String,Integer>> arrayList = new ArrayList<Entry<String, Integer>>(set);
-
- Collections.sort(arrayList,new Comparator<Entry<String,Integer>>(){
- @Override
- public int compare(Entry<String, Integer> o1,Entry<String, Integer> o2) {
-
- int i = o1.getValue()-o2.getValue();
-
- // TODO Auto-generated method stub
- return -i;
- }
- });
-
- System.out.println(arrayList);
-
- // List<Entry<String,Integer>> asList = Arrays.asList(set);
-
-
- }
- }
复制代码 |
|