开发者

Size of a list in Java [duplicate]

This question already has answers here: 开发者_JAVA技巧 Closed 12 years ago.

Possible Duplicate:

How many data a list can hold at the maximum

What is the maximum number of elements a list can hold?


Assuming you mean implementations of the java.util.List interface, methods like get() and size() use int, so the upper theoretical boundary would be Integer.MAX_VALUE entries. You might run out of memory before you reach this limit though!

The index type in Java arrays is int too, so you're definitely limited to Integer.MAX_VALUE entries for regular arrays.


If you're talking about an ArrayList, they're indexed using integers (which are always signed in Java), so they can theoretically hold 2^31 elements (not 2^32). At that point you're probably going to have memory issues anyway.


LinkedList is also an implementation of List which stores the elements as a Linked List. So theoretically its size is equivalent to the amount of memory you can allocate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜