开发者

How many elements can a Stack store in Java?

Is there 开发者_如何转开发a maximum number of elements that can be stored in a stack? Is the only limitation the amount of storage available to the system?

For clarity, I'm referring to java.util.Stack.


If you are taling about java.util.Stack, then the limit is Integer.MAX_VALUE which is about 2 billion. However if you let it grow naturally, you get an exception if you add more than about 1.3 billion (10 * 2^28) as it will try to grow the underlying array to a size larger than is allowed.

IMHO Stack is a legacy class replaced in Java 1.2 (1998) I don't suggest you use it.


The storage capability is normally limited by memory available, either heap memory for stack data structures or stack memory for the call stack.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜