public class List extends ResizeableArrayObject
Modifier and Type | Field and Description |
---|---|
protected int |
size |
array
Constructor and Description |
---|
List()
create a new list
|
List(int initialSize)
Create a new list with a given initial size of the backing array
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.Object o)
Add an object to the end of the list
|
void |
clear()
clear all elements from the list
|
boolean |
contains(java.lang.Object object) |
java.lang.Object |
get(int index) |
boolean |
isEmpty() |
void |
remove(int index)
Remove an element from the list
|
boolean |
remove(java.lang.Object object)
remove the first element in the list where
Object.equals(Object) is true |
void |
set(int index,
java.lang.Object obj)
set the value at a given index in the list
|
int |
size() |
arraySize, ensureSize
protected int size
public List()
public List(int initialSize)
initialSize
- the initial size of the backing arraypublic boolean isEmpty()
public int size()
public void add(java.lang.Object o)
o
- the object to be addedpublic void remove(int index) throws java.lang.IndexOutOfBoundsException
index
- the index of the element to be removedjava.lang.IndexOutOfBoundsException
- if the index is not in the listpublic void clear()
public java.lang.Object get(int index)
index
- public boolean remove(java.lang.Object object)
Object.equals(Object)
is trueobject
- public boolean contains(java.lang.Object object)
object
- Object.equals(Object)
is true)public void set(int index, java.lang.Object obj)
index
- the index where the object should be putobj
- the new value at the index