Java中栈可以存储多少个元素?
堆栈中可以存储的元素是否有最大数量?唯一的限制是系统可用的存储量吗?
为了清楚起见,我指的是 java.util.Stack。
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
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您谈论的是
java.util.Stack
,那么限制是Integer.MAX_VALUE
,约为 20 亿。但是,如果让它自然增长,如果添加超过约 13 亿 (10 * 2^28),则会出现异常,因为它会尝试将基础数组增长到大于允许的大小。恕我直言,Stack 是 Java 1.2 (1998) 中替换的遗留类,我不建议您使用它。
If you are taling about
java.util.Stack
, then the limit isInteger.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.