T - is the type parameter.public class MyArrayList<T> extends java.lang.Object implements MyList<T>, java.util.RandomAccess, java.lang.Cloneable
| Constructor and Description |
|---|
MyArrayList()
This constructor will set the internal array to an Object array of size 10.
|
MyArrayList(int capacity)
This constructor will set the internal array to an Object array of size
specified by the user using parameter capacity.
|
MyArrayList(MyArrayList<T> ma)
This is the copy constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int i,
T item)
Add (insert) item to the ith position of this MyList.
|
void |
add(T item)
Add item to the end of this List.
|
java.lang.Object |
clone()
This is the clone method
|
T |
get(int i)
Get the element at index i
|
int |
indexOf(java.lang.Object item)
Find the index of the input item in this MyList.
|
java.util.Iterator<T> |
iterator()
For MyArrayList iterator
|
T |
remove(int i)
Remove the item at the ith position from this MyArrayList.
|
T |
set(int i,
T item)
Replace the element at i with new one provided by the parameter item.
|
int |
size() |
java.lang.Object[] |
toArray()
This method return an Object array of the same size that contains every element
in this MyList;
|
<K> K[] |
toArray(K[] a)
Returns an array that contains every element in this MyList.
|
java.lang.String |
toString()
Override toString method so it will return a String started and ended by [ and ],
respectively, in which all elements' results of their own toString() will be
concatenated according to their order in the list.
|
public MyArrayList()
public MyArrayList(int capacity)
capacity - is the length the internal arraypublic MyArrayList(MyArrayList<T> ma)
ma - MyArrayList to be copiedpublic java.lang.Object clone()
clone in class java.lang.Objectpublic int size()
public T get(int i)
MyListget in interface MyList<T>i - is an int.java.lang.ArrayIndexOutOfBoundsException - will be thrown if parameter i is not a legitimate index.MyList.get(int)public T set(int i, T item)
MyListset in interface MyList<T>i - is an int.item - is a T.java.lang.ArrayIndexOutOfBoundsException - if parameter i is not a legitimate index.MyList.set(int, java.lang.Object)public int indexOf(java.lang.Object item)
public void add(T item)
MyListadd in interface MyList<T>item - is a T.MyList.add(java.lang.Object)public void add(int i,
T item)
MyListadd in interface MyList<T>i - is an int.item - is a T.java.lang.ArrayIndexOutOfBoundsException - if parameter i is not a legitimate index.MyList.add(int, java.lang.Object)public T remove(int i)
MyListremove in interface MyList<T>i - is an int.java.lang.ArrayIndexOutOfBoundsException - if parameter i is not a legitimate index.MyList.remove(int)public java.lang.Object[] toArray()
MyListtoArray in interface MyList<T>MyList.toArray()public <K> K[] toArray(K[] a)
public java.lang.String toString()
MyListtoString in interface MyList<T>toString in class java.lang.ObjectMyList.toString()