Methods Summary |
---|
public void | add(int x)Add an int to the array, growing the array if necessary
if (nums.length == size) resize(nums.length*2); // Grow array, if needed.
nums[size++] = x; // Store the int in it.
|
public int | elementAt(int index)Return an element of the array // Index of next unused element of nums[].
if (index >= size) throw new ArrayIndexOutOfBoundsException(index);
else return nums[index];
|
private void | readObject(java.io.ObjectInputStream in)Compute the transient size field after deserializing the array
in.defaultReadObject(); // Read the array normally.
size = nums.length; // Restore the transient field.
|
protected void | resize(int newsize)An internal method to change the allocated size of the array
int[] oldnums = nums;
nums = new int[newsize]; // Create a new array.
System.arraycopy(oldnums, 0, nums, 0, size); // Copy array elements.
|
private void | writeObject(java.io.ObjectOutputStream out)Get rid of unused array elements before serializing the array
if (nums.length > size) resize(size); // Compact the array.
out.defaultWriteObject(); // Then write it out normally.
|