可以存储在HashMap中的键(对象)的数量的理论极限? [英] Theoretical limit for number of keys (objects) that can be stored in a HashMap?

查看:488
本文介绍了可以存储在HashMap中的键(对象)的数量的理论极限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于可以存储在HashMap中的关键条目的数量是否存在理论上的限制,还是纯粹依赖于可用的堆内存?

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


观看该类的文档,我会说理论限制是 Integer.MAX_VALUE 31 -1 = 2147483647)元素。

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



星期五om HashMap.size()
$ b


返回: 此映射中键值映射的数量


注意:此问题与< a href =https://stackoverflow.com/a/3768038/276052>列表最多可容纳多少个数据。





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


我想说这取决于你需要存储什么以及你需要什么类型的访问。所有内置收藏品都可能为大批量优化。


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 heap memory available?

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

解决方案

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 ?

Looking at the documentation of that class, I would say that the theoretical limit is Integer.MAX_VALUE (231-1 = 2147483647) elements.

This is because to properly implement this class, the size() method is obliged to return an int representing the number of key/value pairs.

From the documentation of HashMap.size()

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

Note: This question is very similar to 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)?

I would say it depends on what you need to store and what type of access you require. All built in collections are probably well optimized for large quantities.

这篇关于可以存储在HashMap中的键(对象)的数量的理论极限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆