010_TreeMap键使用Comparator排序
生活随笔
收集整理的這篇文章主要介紹了
010_TreeMap键使用Comparator排序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. TreeMap鍵使用Comparator排序
import java.util.Comparator; import java.util.Map.Entry; import java.util.TreeMap; /*** TreeMap鍵使用Comparator排序 */ public class TreeMapComparator {public static void main(String[] args) {TreeMap<String, Object> tm = new TreeMap<String, Object>(new Comparator<String>() {public int compare(String o1, String o2) {return o2.compareTo(o1);}});tm.put("name", "zhangsan");tm.put("age", 28);tm.put("sex", "male");tm.put("height", 175);tm.put("weight", 75);for (Entry<String, Object> kv : tm.entrySet()) {System.out.println(kv.getKey() + ":" + kv.getValue());}} }?
總結
以上是生活随笔為你收集整理的010_TreeMap键使用Comparator排序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 009_TreeSet对实现了Compa
- 下一篇: 011_TreeMap对键实现了Comp