Java 数组有最大大小吗? [英] Do Java arrays have a maximum size?
本文介绍了Java 数组有最大大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Java 数组可以包含的元素数量有限制吗?如果是,那是什么?
Is there a limit to the number of elements a Java array can contain? If so, what is it?
推荐答案
还没看到正确答案,虽然很容易测试.
Haven't seen the right answer, even though it's very easy to test.
在最近的 HotSpot VM 中,正确答案是 Integer.MAX_VALUE - 5
.一旦你超越了这个:
In a recent HotSpot VM, the correct answer is Integer.MAX_VALUE - 5
. Once you go beyond that:
public class Foo {
public static void main(String[] args) {
Object[] array = new Object[Integer.MAX_VALUE - 4];
}
}
你得到:
Exception in thread "main" java.lang.OutOfMemoryError:
Requested array size exceeds VM limit
这篇关于Java 数组有最大大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文