| Constructor and Description |
|---|
SparseArray()
Creates an empty sparse array.
|
SparseArray(int initialCapacity)
Creates an empty sparse array with the given capacity.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all elements from this array.
|
SparseArray<E> |
clone() |
boolean |
containsElement(E element)
Checks whether this array contains the given element.
|
boolean |
containsIndex(int index)
Checks whether this array contains the given index.
|
void |
ensureCapacity(int minCapacity)
Increases the capacity of this array, if necessary, to ensure that it can hold at least the given number of elements.
|
void |
forEach(BiConsumer<Integer,? super E> action)
Performs the given action for each element in this array until all elements have been processed or the action throws an exception.
|
E |
get(int index)
Returns the element at the given index in this array.
|
E |
getOrDefault(int index,
E defaultValue)
Returns the element at the given index in this array.
|
int |
indexOf(E element)
Returns the index of the first occurrence of the specified element in this array.
|
boolean |
isEmpty()
Checks whether this array is empty.
|
int |
lastIndexOf(E element)
Returns the index of the last occurrence of the specified element in this array.
|
E |
remove(int index)
Removes and returns the element at the given index in this array.
|
void |
set(int index,
E value)
Sets the element at the given index in this array to the given value.
|
void |
setIfAbsent(int index,
E value)
If there is no element in this array at the given index, sets it to the given value.
|
int |
size()
Returns the number of elements in this array.
|
String |
toString() |
void |
trimToSize()
Trims the capacity of this array to its current size.
|
public SparseArray()
public SparseArray(int initialCapacity)
public void clear()
public SparseArray<E> clone()
public boolean containsElement(E element)
IllegalArgumentException - if element is nullpublic boolean containsIndex(int index)
IllegalArgumentException - if index is negativepublic void ensureCapacity(int minCapacity)
IllegalArgumentException - if minCapacity is negativepublic void forEach(BiConsumer<Integer,? super E> action)
IllegalArgumentException - if action is nullpublic E get(int index)
null if there is no element in this array at the given index.IllegalArgumentException - if index is negativepublic E getOrDefault(int index, E defaultValue)
IllegalArgumentException - if index is negativepublic int indexOf(E element)
-1 if this array does not contain the element.IllegalArgumentException - if element is nullpublic boolean isEmpty()
public int lastIndexOf(E element)
-1 if this array does not contain the element.IllegalArgumentException - if element is nullpublic E remove(int index)
null if there is no element in this array at the given index.IllegalArgumentException - if index is negativepublic void set(int index,
E value)
IllegalArgumentException - if index is negativeIllegalArgumentException - if value is nullpublic void setIfAbsent(int index,
E value)
IllegalArgumentException - if index is negativeIllegalArgumentException - if value is nullpublic int size()
public void trimToSize()