使用SortedMap对HashMap排序

HashMap map=new HashMap(); map.put("1","11"); map.put("2", "22"); map.put("3", "33"); for (Entry entry: map.entrySet()) { System.out.println("排序之前:"+entry.getKey()+" 值"+entry.getValue()); } System.out.println("======================================================"); SortedMap sort=new TreeMap(map); Set> entry1=sort.entrySet(); Iterator> it=entry1.iterator(); while(it.hasNext()) { Entry entry=it.next(); System.out.println("排序之后:"+entry.getKey()+" 值"+entry.getValue()); }

你可能感兴趣的:(java)