ArrayListJava中的最大容量是多少?由于ArrayList在内部使用数组,它的容量将是Integer.MAX_VALUE,对吗?
此代码显示的最大容量ArrayList为Integer.MAX_VALUE:
public class ArrayList<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable
{
transient Object[] elementData; // non-private to simplify nested class access
/**
* The size of the ArrayList (the number of elements it contains).
*
* @serial
*/
private int size;
/**
* The maximum size of array to allocate (unless necessary).
* Some VMs reserve some header words in an array.
* Attempts to allocate larger arrays may …Run Code Online (Sandbox Code Playgroud)