Constructor and Description |
---|
ArrayList()
Constructor creates a default empty array list.
|
ArrayList(int capacity)
Constructor to create an array list of some initial size
|
ArrayList(Object[] arr)
Constructor creates an array list from an existing basic array.
|
ArrayList(Object[] arr,
int ofs,
int len)
Constructor creates an array list from a portion of an existing array.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E item)
Adds the item to the end of the array list.
|
void |
add(int index,
E item)
Inserts the supplied item at the specified position.
|
int |
capacity()
Returns the current capacity of the array list and not the count of elements.
|
void |
clear()
Clears the array list.
|
Object |
clone()
Clones the array list.
|
boolean |
contains(Object item)
Indicates whether or not the item exists in the array list.
|
void |
ensureCapacity(int cnt)
Ensures that the array list has enough capacity.
|
void |
fill(int index,
int cnt,
E item)
Stores the provided item in a range of the array list.
|
E |
get(int index)
Obtain the element at the provided index.
|
int |
indexOf(Object item)
Returns the index of the first matching item.
|
int |
indexOf(Object item,
int index)
Returns the the index of the first matching item located at or after
the supplied index.
|
Iterator<E> |
iterator()
Basic requirement to make this class work with for-each.
|
int |
lastIndexOf(Object item)
Returns the last occurrence of the supplied item.
|
int |
lastindexOf(Object item,
int index)
Returns the last occurrence of the supplied item up to and including the
supplied index.
|
E |
remove(int index)
Removes the item at the specified index.
|
boolean |
remove(Object item)
Removes the first occurrence of an item.
|
E |
set(int index,
E item)
Stores a new item at the specified index.
|
void |
setSize(int cnt)
Forces the internal array to a specific size.
|
int |
size()
Returns the count of elements stored in the array list.
|
Object[] |
toArray()
Obtains a copy of the array list.
|
void |
trimToSize()
Trims the array list to fit only the existing data.
|
public ArrayList()
public ArrayList(int capacity)
capacity
- public ArrayList(Object[] arr)
arr
- existing basic array.public ArrayList(Object[] arr, int ofs, int len)
arr
- existing basic arrayofs
- offset into the arraylen
- length of new array listpublic Object clone()
public int size()
public void clear()
public Object[] toArray()
public E get(int index)
index
- object in the array list to returnpublic void fill(int index, int cnt, E item)
index
- staring index for the fillcnt
- total number of item references to storeitem
- the item to be storedpublic E set(int index, E item)
index
- position to updateitem
- the item to be storedpublic boolean add(E item)
item
- item to be appendedtrue
if successfulpublic void add(int index, E item)
index
- position of insertionitem
- item to be storedpublic E remove(int index)
index
- position of item to removepublic boolean remove(Object item)
item
- item to be removedtrue
if the item was detected and removed.public int capacity()
public void ensureCapacity(int cnt)
cnt
- requested new size for the array listpublic void trimToSize()
public void setSize(int cnt)
cnt
- desired size.public boolean contains(Object item)
item
- the item to look fortrue
if the item exists.public int indexOf(Object item)
item
- to be matchedpublic int indexOf(Object item, int index)
item
- to be matchedindex
- starting pointpublic int lastIndexOf(Object item)
item
- item to search forpublic int lastindexOf(Object item, int index)
item
- item to search forindex
- the position to search back from (inclusive)