1. //默认构造函数,按照key的自然顺序排列
    2. // 如果key是自定义类,必须实现Comparable接口
    3. public TreeMap() {
    4. comparator = null;
    5. }
    1. //传递Comparator具体实现,按照该实现规则进行排序
    2. public TreeMap(Comparator<? super K> comparator) {
    3. this.comparator = comparator;
    4. }
    1. public TreeMap(Map<? extends K, ? extends V> m) {
    2. comparator = null;
    3. putAll(m);
    4. }
    1. public TreeMap(SortedMap<K, ? extends V> m) {
    2. comparator = m.comparator();
    3. try {
    4. buildFromSorted(m.size(), m.entrySet().iterator(), null, null);
    5. } catch (java.io.IOException cannotHappen) {
    6. } catch (ClassNotFoundException cannotHappen) {
    7. }
    8. }