documentation for HashMap包含以下语句:
Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important.
谁能解释一下。我没有看到任何改变或影响 HashMap 负载因子的方法
最佳答案
当您将 HashMap 声明为 constructor 的一部分时参数,您可以为其提供初始容量和负载因子:
HashMap(int initialCapacity, float loadFactor)
Constructs an empty HashMap with the specified initial capacity and load factor.
你也可以看看this SO thread了解有关负载因子和初始容量的一些信息。
关于java - 初始容量如何影响 HashMap 的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12713260/