[英]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
. 为了清楚起见,我指的是java.util.Stack
。
If you are taling about java.util.Stack
, then the limit is Integer.MAX_VALUE
which is about 2 billion. 如果您要讨论java.util.Stack
,则限制为Integer.MAX_VALUE
,大约为20亿。 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. 但是,如果让它自然增长,则添加超过13亿(10 * 2 ^ 28)的内容会产生异常,因为它会尝试将基础数组增长到大于允许的大小。
IMHO Stack is a legacy class replaced in Java 1.2 (1998) I don't suggest you use it. IMHO Stack是Java 1.2(1998)中取代的旧类,我不建议您使用它。
存储能力通常受可用内存(用于堆栈数据结构的堆内存或用于调用堆栈的堆栈内存)限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.