Java TreeSet 的底层结构是什么?

What structure is underlying Java TreeSet?

Java TreeSet是红黑树自平衡结构。

但是存储数据的结构是什么?数组还是链表?

TreeSetTreeMap 支持(以类似的方式 HashSetHashMap 支持)。如果您查看 TreeSet 构造函数:

public TreeSet() {
    this(new TreeMap<E,Object>());
}

TreeMap 使用 TreeMap.Entry class:

表示的节点在内部存储数据
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;
...

那里没有额外的数组或列表。