本文共 787 字,大约阅读时间需要 2 分钟。
import java.util.*;public class Main { public static void main(String[] args) { Mapm = new HashMap (); m.put(1934, "意大利"); m.put(1938, "意大利"); m.put(1950, "乌拉圭"); m.put(1954, "西德"); m.put(1958, "巴西"); m.put(1962, "巴西"); m.put(1966, "英格兰"); List > list =new LinkedList >(m.entrySet()); Collections.sort(list,new Comparator >() {//根据Value排序 @Override public int compare(Entry o1, Entry o2) { return o1.getValue().compareTo(o2.getValue()); } }); Map mp= new LinkedHashMap (); for(Map.Entry entry:list) { mp.put(entry.getKey(), entry.getValue()); } System.out.println(m); for (Entry entry : mp.entrySet()) { //遍历 System.out.println(entry.getKey()+"="+entry.getValue()); } }}
转载地址:http://hwwzb.baihongyu.com/