1121

6. TreeMap详解

简介

TreeMap平时没怎么用过,简单研究一下

主要结构

    private final Comparator<? super K> comparator; //比较器,默认是自然比较,自己可以通过构造函数传入,compareTo决定了key不能为null
    static final class Entry<K,V> implements Map.Entry<K,V> {
        K key;
        V value;
        Entry<K,V> left;
        Entry<K,V> right;
        Entry<K,V> parent;
        boolean color = BLACK;
    }

总体看了一下之后,发现就是个红黑树,通过Comparator实现有序,线程不安全

posted @ 2020-07-31 16:20  凡夫俗子90  阅读(72)  评论(0)    收藏  举报