FileDocCategorySizeDatePackage
arrayList.javaAPI DocExample2894Fri Nov 03 10:53:54 GMT 2006None

ArrayList

public class ArrayList extends AbstractList implements RandomAccess

Fields Summary
private E[]
arr
private int
size
Constructors Summary
public ArrayList(int cap)

       
	if (cap < 0)
	    throw new IllegalArgumentException("Illegal Capacity: "+cap);
	arr = (E[])new Object[cap];  // unchecked
    
public ArrayList()

 this(10); 
public ArrayList(Collection c)

	this(c.size()); addAll(c);
    
Methods Summary
public voidadd(int i, E elt)

	checkBounds(i,size+1);
	ensureCapacity(size+1);
	System.arraycopy(arr,i,arr,i+1,size-i);
	arr[i] = elt;  size++;
    
private voidcheckBounds(int i, int size)

	if (i < 0 || i >= size)
	    throw new IndexOutOfBoundsException("Index: "+i+", Size: "+size);
    
public voidensureCapacity(int mincap)

        int oldcap = arr.length;
        if (mincap > oldcap) {
            int newcap = Math.max(mincap, (oldcap*3)/2+1);
            E[] oldarr = arr;
            arr = (E[])new Object[newcap];  // unchecked cast
            System.arraycopy(oldarr,0,arr,0,size);
        }
    
public Eget(int i)

	checkBounds(i,size); return arr[i];
    
public Eremove(int i)

	checkBounds(i,size);
	E old = arr[i];  arr[i] = null;  size--;
	System.arraycopy(arr,i+1,arr,i,size-i);
	return old;
    
public Eset(int i, E elt)

	checkBounds(i,size); E old = arr[i]; arr[i] = elt; return old;
    
public intsize()

 return size; 
public T[]toArray(T[] newarr)

	if (newarr.length < size) {
	    newarr = GenericArray.newInstance(newarr, size);
	}
	System.arraycopy(arr,0,newarr,0,size);
	if (size < newarr.length) newarr[size] = null;
	return newarr;