本文介绍了可以存储在HashMap中的键(对象)的数量的理论极限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 对于可以存储在HashMap中的关键条目的数量是否存在理论上的限制,还是纯粹依赖于可用的堆内存? 另外,哪个数据结构最适合存储大量对象(比如说几十万个对象)? 观看该类的文档,我会说理论限制是 Integer.MAX_VALUE 这是因为要正确实现这个类, size() code> 方法必须返回 int ,表示键/值对的数目。 星期五om HashMap.size() $ b 注意:此问题与列表最多可容纳多少个数据。 我想说这取决于你需要存储什么以及你需要什么类型的访问。所有内置收藏品都可能为大批量优化。 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)? 解决方案 Looking at the documentation of that class, I would say that the theoretical limit is Integer.MAX_VALUE (2-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()Note: This question is very similar to How many data a list can hold at the maximum.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中的键(对象)的数量的理论极限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 11:28