java Java的TreeSet和TreeMap用的是什么树?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3580761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 02:30:44  来源:igfitidea点击:

What kind of tree is used in Java's TreeSet and TreeMap?

javacollectionstree

提问by Craig P. Motlin

Are they AVL trees, red-black trees, or something else?

它们是 AVL 树、红黑树还是其他什么树?

回答by Kru

Red-blacktrees as described in the first line of the javadoc.

如 javadoc 的第一行中所述的红黑树。

回答by polygenelubricants

From the java.util.TreeMap<K,V>documentation:

java.util.TreeMap<K,V>文档:

A Red-Black treebased NavigableMapimplementation.

一个红黑树的基础NavigableMap实施。

For questions like these, you should always first consult the documentation. The API shouldn't describe ALLof the inner-workings of a class, but elementary informations such as general data structures and algorithms used are usually documented.

对于此类问题,您应该始终首先查阅文档。API 不应描述 a 的所有内部工作原理class,但通常记录基本信息,例如使用的通用数据结构和算法。



Other Java Collections Framework trivias

其他 Java 集合框架琐事

These are all little trivias that are also clearly documented:

这些都是小细节,也清楚地记录在案:

Related questions

相关问题

回答by WonderCsabo

It is a red-black tree in the Oracle desktop Java implementation, but an AVL-tree in Android.

它在 Oracle 桌面 Java 实现中是红黑树,但在 Android 中AVL 树

回答by matt b

The first sentence of the TreeMap Javadocstates:

TreeMap Javadoc的第一句话指出:

A Red-Black tree based NavigableMapimplementation.

基于红黑树的NavigableMap实现。

回答by u290629

TreeSet is based on TreeMap. And they uses red-black tree, red-black tree is a kind of AVL.

TreeSet 基于 TreeMap。他们使用红黑树, 红黑树是 AVL 的一种