java.lang.Object MyArrayList<AnyType>
public class MyArrayList<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 |
---|
public MyArrayList()
Method Detail |
---|
public int size()
public boolean isEmpty()
public AnyType get(int idx)
idx
- the index to search in.
java.lang.ArrayIndexOutOfBoundsException
- if index is out of range.public AnyType set(int idx, AnyType newVal)
idx
- the index to change.newVal
- the new value.
java.lang.ArrayIndexOutOfBoundsException
- if index is out of range.public void ensureCapacity(int newCapacity)
public boolean add(AnyType x)
x
- any object.
public void add(int idx, AnyType x)
x
- any object.public AnyType remove(int idx)
idx
- the index of the object.
public void clear()
public java.util.Iterator<AnyType> iterator()
iterator
in interface java.lang.Iterable<AnyType>
public java.lang.String toString()
toString
in class java.lang.Object