Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CAPACITY |
Constructor and Description |
---|
BasicArrayList()
Default constructor - initializes the list to have a capacitiy equal to
the DEFAULT_CAPACITY and a logical size of zero.
|
BasicArrayList(int capacity)
Constructor - initializes the list to have the specified capacity (but
never less than the DEFAULT_CAPACITY) and a logical size of 0.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
java.lang.Object o)
Adds (inserts) the specfied element at the specfied index of the list
- note that it does not overwrite any existing data at that location.
|
void |
add(java.lang.Object o)
Adds the specfied element to the logical end of the list.
|
int |
capacity()
Provides access to the current capacity (.length) of the private array to
allow for rigorous unit testing - note that this method is not available
in the Java Standard Library ArrayList class.
|
void |
clear()
Clears the list of its contents - the size of the list should be zero
and its capacity should be unaffected.
|
boolean |
contains(java.lang.Object o)
Using the provided element's equals method, this method determines
if the list contains the specified element or not.
|
java.lang.Object |
get(int index)
Returns a reference to the element at the specified index.
|
int |
indexOf(java.lang.Object element)
Using the provided element's equals method, this method returns the
index of the first element in the list that is equal to the provided
element, if any.
|
java.lang.Object |
remove(int index)
Removes (and returns) the specified element from the list.
|
java.lang.Object |
set(int index,
java.lang.Object o)
Sets (replaces) the element at the specfied index.
|
int |
size()
The logical size of the list (the number of elements that have been
added and not removed).
|
void |
trimToSize()
Frees up any unused space in the list by reducing the capacity of the
list to its size but never less than the DEFAULT_CAPACITY.
|
public static final int DEFAULT_CAPACITY
public BasicArrayList()
public BasicArrayList(int capacity)
capacity
- The capacity of the list. In other words, the size
to allocate for your internal array.public void add(java.lang.Object o)
BasicList
public void add(int index, java.lang.Object o)
BasicList
public java.lang.Object get(int index)
BasicList
public java.lang.Object set(int index, java.lang.Object o)
BasicList
public java.lang.Object remove(int index)
BasicList
public int size()
BasicList
public boolean contains(java.lang.Object o)
BasicList
public void clear()
BasicList
public int indexOf(java.lang.Object element)
BasicList
public int capacity()
public void trimToSize()