java.lang.Cloneablepublic class SparseArray<E>
extends java.lang.Object
implements java.lang.Cloneable
| Constructor | Description |
|---|---|
SparseArray() |
Creates an empty sparse array.
|
SparseArray(int initialCapacity) |
Creates an empty sparse array with the given capacity.
|
| Modifier and Type | Method | 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(java.util.function.BiConsumer<java.lang.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.
|
java.lang.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()
clone in class java.lang.Objectpublic boolean containsElement(E element)
java.lang.IllegalArgumentException - if element is nullpublic boolean containsIndex(int index)
java.lang.IllegalArgumentException - if index is negativepublic void ensureCapacity(int minCapacity)
java.lang.IllegalArgumentException - if minCapacity is negativepublic void forEach(java.util.function.BiConsumer<java.lang.Integer,? super E> action)
java.lang.IllegalArgumentException - if action is nullpublic E get(int index)
null if there is no element in this array at the given index.java.lang.IllegalArgumentException - if index is negativepublic E getOrDefault(int index, E defaultValue)
java.lang.IllegalArgumentException - if index is negativepublic int indexOf(E element)
-1 if this array does not contain the element.java.lang.IllegalArgumentException - if element is nullpublic boolean isEmpty()
public int lastIndexOf(E element)
-1 if this array does not contain the element.java.lang.IllegalArgumentException - if element is nullpublic E remove(int index)
null if there is no element in this array at the given index.java.lang.IllegalArgumentException - if index is negativepublic void set(int index,
E value)
java.lang.IllegalArgumentException - if index is negativejava.lang.IllegalArgumentException - if value is nullpublic void setIfAbsent(int index,
E value)
java.lang.IllegalArgumentException - if index is negativejava.lang.IllegalArgumentException - if value is nullpublic int size()
public java.lang.String toString()
toString in class java.lang.Objectpublic void trimToSize()