gpt4 book ai didi

java - 可以存储在 HashMap 中的键(对象)数量的理论限制?

转载 作者:IT老高 更新时间:2023-10-28 20:53:43 25 4
gpt4 key购买 nike

对于可以存储在 HashMap 中的键条目的数量是否有理论上的限制,或者最大值是否完全取决于可用的堆内存?

另外,哪种数据结构最适合存储大量对象(比如几十万个对象)?

最佳答案

Is there a theoretical limit for the number of key entries that can be stored in a HashMap or does it purely depend on the heapmemory available ?

the documentation of that class ,我会说理论限制是 Integer.MAX_VALUE (231-1 = 2147483647) 个元素。

这是因为要正确实现这个类,size()方法必须返回一个 int 表示键/值对的数量。

来自 HashMap.size() 的文档

Returns: the number of key-value mappings in this map

注意:这个问题与 How many data a list can hold at the maximum 非常相似。 .


which data structure is the best to store a very large number of objects(say several hundred thousand objects)?

我想说这取决于您需要存储什么以及您需要什么类型的访问权限。所有内置集合可能都针对大批量进行了优化。

关于java - 可以存储在 HashMap 中的键(对象)数量的理论限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4123743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com