HashMap体系结构中Array的初始大小是多少? [英] What is the initial size of Array in HashMap Architecture?
问题描述
我认为 HashMap
的内部存储区使用数组来存储基于键的值,如下面的截图所示。
所以,数组的初始大小16?稍后,如果大小增加,
HashMap
内部重新整理所有内容?如果不是,那么在 HashMap
中数组的初始大小是多少。 另外请确认它是否使用数组或任何其他数据结构,如 ArrayList
?是否意味着数组的初始大小是16
这是OpenJDK / OracleJDK中的默认值。您可以将它设置为更高或更低。
稍后,如果大小增加,HashMap会在内部重新转换为新大小?
当达到加载因子时,它调整并重新排列散列的元素/键
<如果不是,那么HashMap中Array的初始大小是多少?
如果设置它,则使用下一个2的幂。
$ b
是否使用数组或任何其他数据结构,如ArrayList
它使用一个数组和一个额外的数据结构来处理冲突。
Java 8使用平衡树来处理冲突
如果键是可比较的,例如字符串,任何数字,使用树,否则使用列表。
I think HashMap
's internal buckets use an array to store values based on keys as in the below screenshot.
So, is the initial size of the array 16? Later if the size increases the HashMap
internally rehashes everything? If not then what is the initial size of the array in a HashMap
.
Also please confirm whether it uses an array or any other data structure like ArrayList
?
does it mean that the initial size of the Array is 16
This is the default in the OpenJDK/OracleJDK. You can set it higher or lower.
later if size increases the HashMap internally rehashes to new size?
When the load factor is reached it resizes and rearranges the hashed elements/keys
If not then what is the initial size of Array in HashMap
If you set it, the next power of two is used.
whether it uses Array or any other data structure like ArrayList
It uses an array and an additional data structure to handle collisions.
Java 8 uses a balanced tree to handle collisions
If the keys are Comparable e.g. String, any Number, a tree is used, otherwise a list is used.
这篇关于HashMap体系结构中Array的初始大小是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!