Java中栈可以存储多少个元素?

发布于 2024-11-02 09:32:56 字数 78 浏览 3 评论 0原文

堆栈中可以存储的元素是否有最大数量?唯一的限制是系统可用的存储量吗?

为了清楚起见,我指的是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤单情人 2024-11-09 09:32:56

如果您谈论的是 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 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.

枕花眠 2024-11-09 09:32:56

存储能力通常受到可用内存的限制,要么是用于堆栈数据结构的堆内存,要么是用于调用堆栈的堆栈内存。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文