public class MyArrayList<E> extends java.lang.Object implements MyList<E>
Constructor and Description |
---|
MyArrayList()
Create an empty list of default capacity
|
MyArrayList(int capa)
Create an empty list of capacity capa
|
Modifier and Type | Method and Description |
---|---|
void |
add(E e)
Add element o into (the end of) the collection.
|
void |
add(int index,
E element)
Inserts the specified element at the specified position in this list.
|
boolean |
contains(E o)
Returns true if this collection contains the specified element.
|
E |
get(int index)
Returns the element at the specified position in this list.
|
int |
indexOf(E o)
Returns the index of the first occurrence of the specified element
in this list, or -1 if this list does not contain the element.
|
boolean |
isEmpty()
Returns true if this collection contains no elements.
|
int |
lastIndexOf(E o)
Returns the index of the last occurrence of the specified element
in this list, or -1 if this list does not contain the element.
|
void |
remove(E o)
Removes a single instance of the specified element from this
collection, if it is present.
|
E |
remove(int index)
Removes the element at the specified position in this list.
|
E |
set(int index,
E element)
Replaces the element at the specified position in this list with the
specified element
|
int |
size()
Returns the number of elements in this collection.
|
public MyArrayList(int capa)
capa
- the initial capacity. Assume greater than 0.public MyArrayList()
public int size()
MyCollection
size
in interface MyCollection<E>
public boolean isEmpty()
MyCollection
isEmpty
in interface MyCollection<E>
public boolean contains(E o)
MyCollection
contains
in interface MyCollection<E>
o
- element whose presence in this collection is to be tested. Assume o is not null.public E get(int index)
MyList
public E set(int index, E element)
MyList
public void add(E e)
MyCollection
add
in interface MyCollection<E>
e
- element whose presence in this collection is to be ensured. Assume o is not null.public void add(int index, E element)
MyList
public void remove(E o)
MyCollection
remove
in interface MyCollection<E>
o
- element to be removed from this collection, if present. Assume o is not null.public E remove(int index)
MyList
public int indexOf(E o)
MyList
public int lastIndexOf(E o)
MyList
lastIndexOf
in interface MyList<E>
o
- element to search for. Assume o is not null.