V
- the type which is being stored by this class.public class SimpleArrayList<V>
extends java.util.AbstractList<V>
Constructor and Description |
---|
SimpleArrayList()
Constructs an empty list with an initial capacity of ten.
|
SimpleArrayList(java.util.Collection<? extends V> c)
Constructs a list containing the elements of the specified collection, in
the order they are returned by the collection's iterator.
|
SimpleArrayList(int initialCapacity)
Constructs an empty list with the specified initial capacity.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
V element)
Inserts the specified element at the specified position in this list.
|
boolean |
add(V o)
Appends the specified element to the end of this list.
|
boolean |
addAll(java.util.Collection<? extends V> c)
Appends all of the elements in the specified Collection to the end of
this list, in the order that they are returned by the specified
Collection's Iterator.
|
void |
clear()
Removes all of the elements from this list.
|
void |
clearNoGC()
same as clear(), but references to objects are kept internally.
|
boolean |
contains(java.lang.Object elem)
Returns true if this list contains the specified element.
|
void |
ensureCapacity(int minCapacity)
Increases the capacity of this ArrayList instance, if
necessary, to ensure that it can hold at least the number of elements
specified by the minimum capacity argument.
|
boolean |
equals(java.lang.Object o)
AbstractList defines equals so that it depends on the objects included.
|
V |
get(int index)
Returns the element at the specified position in this list.
|
int |
hashCode()
AbstractList defines hashCode so that it depends on the objects included.
|
int |
indexOf(java.lang.Object elem)
Searches for the first occurrence of the given argument, testing for
equality using the equals method.
|
int |
indexOf(java.lang.Object elem,
int lastPosition)
Searches for the first occurrence of the given argument, testing for
equality using the == method.
|
boolean |
isEmpty()
Tests if this list has no elements.
|
int |
lastIndexOf(java.lang.Object elem)
Returns the index of the last occurrence of the specified object in this
list.
|
V |
pop()
It removes and returns the last element in the list.
|
void |
push(V element)
It inserts the element at the end of the list
|
V |
remove(int index)
Removes the element at the specified position in this list.
|
boolean |
remove(java.lang.Object o)
Removes a single instance of the specified element from this list, if it
is present (optional operation).
|
V |
set(int index,
V element)
Replaces the element at the specified position in this list with the
specified element.
|
void |
setElementAt(V element,
int index)
Replaces the element at the specified position in this list with the
specified element.
|
int |
size()
Returns the number of elements in this list.
|
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this list in the
correct order.
|
<T> T[] |
toArray(T[] a)
Returns an array containing all of the elements in this list in the
correct order; the runtime type of the returned array is that of the
specified array.
|
java.lang.String |
toString()
Check if the given index is in range.
|
void |
trimToSize()
Trims the capacity of this ArrayList instance to be the list's
current size.
|
public SimpleArrayList()
public SimpleArrayList(java.util.Collection<? extends V> c)
c
- the collection whose elements are to be placed into this list.java.lang.NullPointerException
- if the specified collection is null.public SimpleArrayList(int initialCapacity)
initialCapacity
- the initial capacity of the list.public int hashCode()
public boolean equals(java.lang.Object o)
public boolean add(V o)
public void add(int index, V element)
public boolean addAll(java.util.Collection<? extends V> c)
public void clear()
public void clearNoGC()
public boolean contains(java.lang.Object elem)
contains
in interface java.util.Collection<V>
contains
in interface java.util.List<V>
contains
in class java.util.AbstractCollection<V>
elem
- element whose presence in this list is to be tested.true
if the specified element is present;
false
otherwise.public void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacity.public V get(int index)
public V pop()
public void push(V element)
element
- the added element.public int indexOf(java.lang.Object elem)
public int indexOf(java.lang.Object elem, int lastPosition)
elem
- an object.lastPosition
- last index to which it should check.public boolean isEmpty()
public int lastIndexOf(java.lang.Object elem)
public V remove(int index)
public boolean remove(java.lang.Object o)
public V set(int index, V element)
public void setElementAt(V element, int index)
index
- index of element to replace.element
- element to be stored at the specified position.public int size()
public java.lang.Object[] toArray()
public <T> T[] toArray(T[] a)
If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.
toArray
in interface java.util.Collection<V>
toArray
in interface java.util.List<V>
toArray
in class java.util.AbstractCollection<V>
T
- the type which is being stored by a SimpleArrayList.a
- the array into which the elements of the list are to be
stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.java.lang.ArrayStoreException
- if the runtime type of a is not a supertype of the runtime
type of every element in this list.public java.lang.String toString()
toString
in class java.util.AbstractCollection<V>
public void trimToSize()