Class MyArrayList<AnyType>

java.lang.Object
  extended by MyArrayList<AnyType>
All Implemented Interfaces:
java.lang.Iterable<AnyType>

public class MyArrayList<AnyType>
extends java.lang.Object
implements java.lang.Iterable<AnyType>


Constructor Summary
MyArrayList()
          Construct an empty ArrayList.
 
Method Summary
 boolean add(AnyType x)
          Adds an item to this collection, at the end.
 void add(int idx, AnyType x)
          Adds an item to this collection, at the specified index.
 void clear()
          Change the size of this collection to zero.
 void ensureCapacity(int newCapacity)
           
 AnyType get(int idx)
          Returns the item at position idx.
 boolean isEmpty()
          Returns true if this collection is empty.
 java.util.Iterator<AnyType> iterator()
          Obtains an Iterator object used to traverse the collection.
 AnyType remove(int idx)
          Removes an item from this collection.
 AnyType set(int idx, AnyType newVal)
          Changes the item at position idx.
 int size()
          Returns the number of items in this collection.
 java.lang.String toString()
          Returns a String representation of this collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MyArrayList

public MyArrayList()
Construct an empty ArrayList.

Method Detail

size

public int size()
Returns the number of items in this collection.

Returns:
the number of items in this collection.

isEmpty

public boolean isEmpty()
Returns true if this collection is empty.

Returns:
true if this collection is empty.

get

public AnyType get(int idx)
Returns the item at position idx.

Parameters:
idx - the index to search in.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is out of range.

set

public AnyType set(int idx,
                   AnyType newVal)
Changes the item at position idx.

Parameters:
idx - the index to change.
newVal - the new value.
Returns:
the old value.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is out of range.

ensureCapacity

public void ensureCapacity(int newCapacity)

add

public boolean add(AnyType x)
Adds an item to this collection, at the end.

Parameters:
x - any object.
Returns:
true.

add

public void add(int idx,
                AnyType x)
Adds an item to this collection, at the specified index.

Parameters:
x - any object.

remove

public AnyType remove(int idx)
Removes an item from this collection.

Parameters:
idx - the index of the object.
Returns:
the item was removed from the collection.

clear

public void clear()
Change the size of this collection to zero.


iterator

public java.util.Iterator<AnyType> iterator()
Obtains an Iterator object used to traverse the collection.

Specified by:
iterator in interface java.lang.Iterable<AnyType>
Returns:
an iterator positioned prior to the first element.

toString

public java.lang.String toString()
Returns a String representation of this collection.

Overrides:
toString in class java.lang.Object