MutableIntList
public final class MutableIntList extends IntList
MutableIntList is a MutableList-like collection for Int values. It allows storing and retrieving the elements without boxing. Immutable access is available through its base class IntList, which has a List-like interface.
This implementation is not thread-safe: if multiple threads access this container concurrently, and one or more threads modify the structure of the list (insertion or removal for instance), the calling code must provide the appropriate synchronization. It is also not safe to mutate during reentrancy -- in the middle of a forEach, for example. However, concurrent reads are safe.
Summary
Public constructors |
|---|
MutableIntList(int initialCapacity)Creates a |
Public methods |
|
|---|---|
final boolean |
add(int element)Adds |
final void |
Adds |
final boolean |
Adds all |
final boolean |
Adds all |
final boolean |
Adds all |
final boolean |
Adds all |
final void |
clear()Removes all elements in the |
final void |
ensureCapacity(int capacity)Ensures that there is enough space to store |
final int |
Returns the total number of elements that can be held before the |
final void |
minusAssign(int element)
|
final void |
minusAssign(@NonNull int[] elements)Removes all |
final void |
minusAssign(@NonNull IntList elements)Removes all |
final void |
plusAssign(int element)
|
final void |
plusAssign(@NonNull int[] elements)Adds all |
final void |
plusAssign(@NonNull IntList elements)Adds all |
final boolean |
remove(int element)Removes |
final boolean |
Removes all |
final boolean |
Removes all |
final int |
Removes the element at the given |
final void |
removeRange(@IntRange(from = 0) int start, @IntRange(from = 0) int end)Removes items from index |
final boolean |
Keeps only |
final boolean |
Keeps only |
final int |
|
final void |
sort()Sorts the |
final void |
Sorts the |
final void |
trim(int minCapacity)Reduces the internal storage. |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
MutableIntList
public MutableIntList(int initialCapacity)
Creates a MutableIntList with a capacity of initialCapacity.
Public methods
add
public final boolean add(int element)
Adds element to the MutableIntList and returns true.
add
public final void add(@IntRange(from = 0) int index, int element)
Adds element to the MutableIntList at the given index, shifting over any elements at index and after, if any.
addAll
public final boolean addAll(@NonNull int[] elements)
Adds all elements to the end of the MutableIntList and returns true if the MutableIntList was changed or false if elements was empty.
addAll
public final boolean addAll(@NonNull IntList elements)
Adds all elements to the end of the MutableIntList and returns true if the MutableIntList was changed or false if elements was empty.
addAll
public final boolean addAll(@IntRange(from = 0) int index, @NonNull int[] elements)
Adds all elements to the MutableIntList at the given index, shifting over any elements at index and after, if any.
| Returns | |
|---|---|
boolean |
|
addAll
public final boolean addAll(@IntRange(from = 0) int index, @NonNull IntList elements)
Adds all elements to the MutableIntList at the given index, shifting over any elements at index and after, if any.
| Returns | |
|---|---|
boolean |
|
clear
public final void clear()
Removes all elements in the MutableIntList. The storage isn't released.
| See also | |
|---|---|
trim |
ensureCapacity
public final void ensureCapacity(int capacity)
Ensures that there is enough space to store capacity elements in the MutableIntList.
| See also | |
|---|---|
trim |
getCapacity
public final int getCapacity()
Returns the total number of elements that can be held before the MutableIntList must grow.
| See also | |
|---|---|
ensureCapacity |
minusAssign
public final void minusAssign(int element)
remove from the MutableIntList
minusAssign
public final void minusAssign(@NonNull int[] elements)
Removes all elements from the MutableIntList.
minusAssign
public final void minusAssign(@NonNull IntList elements)
Removes all elements from the MutableIntList.
plusAssign
public final void plusAssign(@NonNull int[] elements)
Adds all elements to the end of the MutableIntList.
plusAssign
public final void plusAssign(@NonNull IntList elements)
Adds all elements to the end of the MutableIntList.
remove
public final boolean remove(int element)
Removes element from the MutableIntList. If element was in the MutableIntList and was removed, true will be returned, or false will be returned if the element was not found.
removeAll
public final boolean removeAll(@NonNull int[] elements)
Removes all elements from the MutableIntList and returns true if anything was removed.
removeAll
public final boolean removeAll(@NonNull IntList elements)
Removes all elements from the MutableIntList and returns true if anything was removed.
removeAt
public final int removeAt(@IntRange(from = 0) int index)
Removes the element at the given index and returns it.
removeRange
public final void removeRange(@IntRange(from = 0) int start, @IntRange(from = 0) int end)
Removes items from index start (inclusive) to end (exclusive).
retainAll
public final boolean retainAll(@NonNull int[] elements)
Keeps only elements in the MutableIntList and removes all other values.
| Returns | |
|---|---|
boolean |
|
retainAll
public final boolean retainAll(@NonNull IntList elements)
Keeps only elements in the MutableIntList and removes all other values.
| Returns | |
|---|---|
boolean |
|
set
public final int set(@IntRange(from = 0) int index, int element)
Sets the value at index to element.
| Returns | |
|---|---|
int |
the previous value set at |
sortDescending
public final void sortDescending()
Sorts the MutableIntList elements in descending order.
trim
public final void trim(int minCapacity)
Reduces the internal storage. If capacity is greater than minCapacity and size, the internal storage is reduced to the maximum of size and minCapacity.
| See also | |
|---|---|
ensureCapacity |