是否有一个长于INT Java列表? [英] Is there a longer than int Java List?

查看:132
本文介绍了是否有一个长于INT Java列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找到一个Java 列表这是最大长度为的最大值。

I can't seem to find a Java List that's max length is long's max value.

请问这样的列表存在吗?

如果有,在哪里?

推荐答案

由于@afsantos说,在的ArrayList 类本身仅限于整数。因为Java数组的局限性MAX_VALUE 项。

As @afsantos says, the ArrayList class is inherently limited to Integer.MAX_VALUE entries because of the limitations of Java arrays.

的LinkedList 没有这个限制,但它是(仍然)昂贵的:

LinkedList doesn't have this limitation, but it is (nonetheless) expensive:


  • 每个条目即被2引用的内存开销加上一个对象头的大小...相比,基于阵列的再presentation只是一个参考。

  • Each entry incurs an memory overhead of 2 references plus the size of an object header ... compared to just one reference for an array-based representation.

索引是 O(N)与操作O(1)一个基于阵列基于列表。

Indexing is an O(N) operation compared with O(1) for an array-based list.

下面是Java库链接支持的巨大的使用元素的直接映射的内存和/或编码在内存中的集合:

Here is a link to Java library that supports huge in-memory collections using direct mapped memory and/or encoding of the elements:

  • http://code.google.com/p/vanilla-java/wiki/HugeCollections

有可能是其他的替代品在那里。

There could be other alternatives out there.

人们还可以设想,使用数组的数组,而不是一个单一的阵列规则阵列列表的大的变体。但是,如果你允许插入列表的中间,就难以/昂贵的达到 O(1)查找。 (这可能是为什么我无法找到与谷歌...为例)

One could also envisage a "big" variant of regular array lists that used an array of arrays rather than a single array. But if you allow insertion into the middle of the list, it becomes difficult / expensive to achieve O(1) lookup. (That might be why I couldn't find an example with Google ...)

这篇关于是否有一个长于INT Java列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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