V
- the type which is being stored by this class.public class SimpleArrayList<V> extends AbstractList<V>
modCount
Constructor and Description |
---|
SimpleArrayList()
Constructs an empty list with an initial capacity of ten.
|
SimpleArrayList(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(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(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(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(Object elem)
Searches for the first occurrence of the given argument, testing for
equality using the equals method.
|
int |
indexOf(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(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(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.
|
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.
|
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.
|
addAll, iterator, listIterator, listIterator, removeRange, subList
containsAll, removeAll, retainAll
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, removeAll, replaceAll, retainAll, sort, spliterator
parallelStream, removeIf, stream
public SimpleArrayList()
public SimpleArrayList(Collection<? extends V> c)
c
- the collection whose elements are to be placed into this list.NullPointerException
- if the specified collection is null.public SimpleArrayList(int initialCapacity)
initialCapacity
- the initial capacity of the list.public int hashCode()
Taking the hash of elementData will make it faster TODO make sure this is what we want
hashCode
in interface Collection<V>
hashCode
in interface List<V>
hashCode
in class AbstractList<V>
public boolean equals(Object o)
Equality of references makes it faster TODO make sure this is what we want
equals
in interface Collection<V>
equals
in interface List<V>
equals
in class AbstractList<V>
public boolean add(V o)
add
in interface Collection<V>
add
in interface List<V>
add
in class AbstractList<V>
o
- element to be appended to this list.public void add(int index, V element)
public boolean addAll(Collection<? extends V> c)
addAll
in interface Collection<V>
addAll
in interface List<V>
addAll
in class AbstractCollection<V>
c
- the elements to be inserted into this list.public void clear()
clear
in interface Collection<V>
clear
in interface List<V>
clear
in class AbstractList<V>
public void clearNoGC()
public boolean contains(Object elem)
contains
in interface Collection<V>
contains
in interface List<V>
contains
in class 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(Object elem)
public int indexOf(Object elem, int lastPosition)
elem
- an object.lastPosition
- last index to which it should check.public boolean isEmpty()
isEmpty
in interface Collection<V>
isEmpty
in interface List<V>
isEmpty
in class AbstractCollection<V>
public int lastIndexOf(Object elem)
lastIndexOf
in interface List<V>
lastIndexOf
in class AbstractList<V>
elem
- the desired element.public V remove(int index)
public boolean remove(Object o)
remove
in interface Collection<V>
remove
in interface List<V>
remove
in class AbstractCollection<V>
o
- element to be removed from this list, if present.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()
size
in interface Collection<V>
size
in interface List<V>
size
in class AbstractCollection<V>
public Object[] toArray()
toArray
in interface Collection<V>
toArray
in interface List<V>
toArray
in class AbstractCollection<V>
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 Collection<V>
toArray
in interface List<V>
toArray
in class 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.ArrayStoreException
- if the runtime type of a is not a supertype of the runtime
type of every element in this list.public String toString()
toString
in class AbstractCollection<V>
public void trimToSize()
Copyright © 2022. All rights reserved.