public class IntArrayList
extends java.lang.Object
Like java.util.ArrayList, its underlying representation can grow dynamically. As well, it is not synchronized.
| Constructor and Description |
|---|
IntArrayList()
Constructs an empty IntArrayList so that its internal data array has size
10 and its standard capacity increment is zero.
|
IntArrayList(java.util.Collection c)
Constructs a IntArrayList containing the intValue() values of the
java.lang.Number objects in the specified collection, in the
order they are returned by the collection's iterator.
|
IntArrayList(int initialCapacity)
Constructs an empty IntArrayList with the specified initial capacity and
with its capacity increment equal to zero.
|
IntArrayList(int[] a)
Constructs an IntArrayList containing the values contained in the
specified array, in the same order.
|
IntArrayList(int initialCapacity,
int capacityIncrement)
Constructs an empty IntArrayList with the specified initial capacity and
capacity increment.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(int element)
Appends the specified element to the end of this IntArrayList.
|
void |
add(int index,
int element)
Inserts the specified element at the specified position in this
IntArrayList.
|
boolean |
addAll(int[] a)
Appends all of the elements in the specified array to the end
of this IntArrayList, in the order of the array.
|
boolean |
addAll(IntArrayList v)
Appends all of the elements in the specified IntArrayList to the end
of this IntArrayList.
|
void |
addAll(int index,
int[] a)
Inserts all the elements in the specified array at the specified
index in this IntArrayList.
|
void |
addAll(int index,
IntArrayList v)
Inserts all of the elements in the specified IntArrayList into this
IntArrayList at the specified position.
|
void |
addElement(int element)
Adds the specified component to the end of this IntArrayList, increasing
its size by one.
|
int |
capacity()
Returns the current capacity of this IntArrayList.
|
void |
clear()
Removes all of the elements from this IntArrayList.
|
void |
clear(int index)
Clears all elements of this IntArraylist at index equal to or
greater than the specified index.
|
java.lang.Object |
clone()
Returns a clone of this IntArrayList.
|
boolean |
contains(int element)
Tests if the specified int is a component in this IntArrayList.
|
boolean |
containsAll(int[] a)
Returns true if this IntArrayList contains all of the elements in the
specified array.
|
boolean |
containsAll(IntArrayList v)
Returns true if this IntArrayList contains all of the elements in the
specified IntArrayList.
|
void |
copyInto(int[] a)
Copies the components of this IntArrayList into the specified array.
|
int |
elementAt(int index)
Returns the component at the specified index.
|
void |
ensureCapacity(int minCapacity)
Increases the capacity of this IntArrayList, if necessary, to ensure
that it can hold at least the number of components specified by the
minimum capacity argument.
|
boolean |
equals(java.lang.Object o)
Compares the specified int with this IntArrayList for equality.
|
int |
firstElement()
Returns the first component (the item at index 0) of this IntArrayList.
|
int |
get(int index)
Returns the element at the specified position in this IntArrayList.
|
int |
hashCode()
Returns the hash code value for this IntArrayList.
|
int |
indexOf(int element)
Searches for the first occurrence of the given int; returns -1 if it
is not found.
|
int |
indexOf(int element,
int index)
Searches for the first occurence of the given int, beginning
the search at index; returns -1 if it is not found.
|
void |
insertElementAt(int element,
int index)
Inserts the specified integer as a component in this IntArrayList at the
specified index.
|
boolean |
isEmpty()
Tests if this IntArrayList has no components.
|
int |
lastElement()
Returns the last component of the IntArrayList.
|
int |
lastIndexOf(int element)
Returns the index of the last occurrence of the specified int in
this IntArrayList; returns -1 if it is not found.
|
int |
lastIndexOf(int element,
int index)
Searches backwards for the specified integer, starting from the
specified index, and returns its index, or -1 if not found.
|
boolean |
removeAll(int[] a)
Removes from this IntArrayList all of its elements that are contained
in the specified array.
|
boolean |
removeAll(IntArrayList v)
Removes from this IntArrayList all of its elements that are contained
in the specified IntArrayList.
|
void |
removeAllElements()
Removes all components from this IntArrayList.
|
boolean |
removeAllFirst(int[] a)
Removes from this IntArrayList the first occurrence of the elements
that are contained in the specified array
|
boolean |
removeAllFirst(IntArrayList v)
Removes from this IntArrayList the first occurrence of the elements
that are contained in the specified IntArrayList.
|
boolean |
removeElement(int element)
Removes the first occurrence of the specified element.
|
void |
removeElementAt(int index)
Deletes the component at the specified index.
|
int |
removeIndex(int index)
Removes the element at the specified position and shifts any subsequent
elements to the left (subtracts one from their indices).
|
void |
removeRange(int fromIndex,
int toIndex)
Removes from this IntArrayList all of the elements whose index is
between fromIndex, inclusive and toIndex, exclusive.
|
boolean |
retainAll(IntArrayList v)
Retains only the elements in this IntArrayList whose elements are
contained in the specified IntArrayList.
|
int |
set(int index,
int element)
Replaces the element at the specified position in this IntArrayList with
the specified element.
|
void |
setElementAt(int element,
int index)
Sets the component at the specified index of this IntArrayList to be the
specified integer.
|
void |
setIncrementFactor(float incrementFactor) |
void |
setLast(int element)
Replaces the element at the last position in this IntArrayList with
the specified element.
|
void |
setSize(int newSize)
Sets the size of this IntArrayList.
|
int |
size()
Returns the number of components in this IntArrayList.
|
int[] |
toArray()
Returns an array containing all of the elements in this IntArrayList in
the correct order.
|
java.lang.String |
toString()
Returns a string representation of this IntArrayList
|
void |
trimToSize()
Trims the capacity of this IntArrayList to be the IntArrayList's current
size.
|
public IntArrayList(int initialCapacity,
int capacityIncrement)
initialCapacity - the initial capacity of the IntArrayList.capacityIncrement - amount by which the capacity is increased on overflow.java.lang.NegativeArraySizeException - if the specified initial capacity is negative.public IntArrayList(int initialCapacity)
initialCapacity - the initial capacity of the IntArrayList.java.lang.NegativeArraySizeException - if the specified initial capacity is negative.public IntArrayList()
public IntArrayList(int[] a)
a - an array of ints.public IntArrayList(java.util.Collection c)
c - the collection whose elements are to be placed into this IntArrayList.java.lang.ClassCastException - if the collection contains a non-number.public final void copyInto(int[] a)
a - the array into which the components get copied.java.lang.IndexOutOfBoundsException - if the array is too small.public final void trimToSize()
public final void ensureCapacity(int minCapacity)
If the current capacity of this IntArrayList is less than minCapacity, then its capacity is increased by replacing its internal data array, kept in the field elementData, with a larger one. The size of the new data array will be the old size plus capacityIncrement, unless the value of capacityIncrement is less than or equal to zero, in which case the new capacity will be the old capacity multiplied by incrementFactor; but if this new size is still smaller than minCapacity, then the new capacity will be minCapacity.
minCapacity - the desired minimum capacity.public final void setSize(int newSize)
newSize - the new size of this IntArrayList.public final int capacity()
public final int size()
public final boolean isEmpty()
public final boolean contains(int element)
element - an int.public final int indexOf(int element)
element - an int.public final int indexOf(int element,
int index)
element - an integer.index - the non-negative index to start searching from.java.lang.IndexOutOfBoundsException - if index is negative.public final int lastIndexOf(int element)
element - the desired component.public final int lastIndexOf(int element,
int index)
element - an integer.index - the non-negative index to start searching from.java.lang.IndexOutOfBoundsException - if index is invalid.public final int elementAt(int index)
index - an index into this IntArrayList.java.lang.ArrayIndexOutOfBoundsException - if the index is invalid.public final int firstElement()
java.lang.ArrayIndexOutOfBoundsException - if this IntArrayList is empty.public final int lastElement()
java.lang.ArrayIndexOutOfBoundsException - if this IntArrayList is empty.public final void setElementAt(int element,
int index)
The index must be a value greater than or equal to 0 and less than the current size of the IntArrayList.
This method is identical in functionality to the set method except that the latter returns the old value that was stored at the specified position and it has its argument in a different order.
element - what the component is to be set to.index - the specified index.java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.public final void removeElementAt(int index)
The index must be a value greater than or equal to 0 and less than the current size of the IntArrayList.
This method is identical in functionality to the removeIndex method except that the removeIndex method returns the old value that was stored at the specified position.
N.B.Because remove(int) is ambiguous, it is not supported for IntArrayLists; its functionality is provided by removeIndex(int) and removeElement(int).
index - the index of the integer to remove.java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.public final void insertElementAt(int element,
int index)
The index must be a value greater than or equal to 0 and less than or equal to the current size of the IntArrayList. (If the index is equal to the current size of the IntArrayList, the new element is appended to the IntArrayList.)
This method is identical in functionality to the add(int, int) method except that the latter method reverses the order of the arguments, to match array usage more closely.
element - the element to insert.index - where to insert the new component.java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.public final void addElement(int element)
This method is identical in functionality to the add(int) method except that the latter returns a boolean.
element - the component to be added.public final void removeAllElements()
public final java.lang.Object clone()
clone in class java.lang.Objectpublic final int[] toArray()
public final int get(int index)
java.lang.ArrayIndexOutOfBoundsException - if the index is invalid.public final int set(int index,
int element)
index - index of element to replace.element - element to be stored at the specified position.java.lang.ArrayIndexOutOfBoundsException - if index is out of range.public final void setLast(int element)
element - element to be stored at the last position.java.lang.ArrayIndexOutOfBoundsException - if index is out of range.public final boolean add(int element)
element - element to be appended to this IntArrayList.public final boolean removeElement(int element)
N.B.Because remove(int) is ambiguous, it is not supported for IntArrayLists; its functionality is provided by removeIndex(int) and removeElement(int).
element - element to be removed from this IntArrayList, if present.public final void add(int index,
int element)
index - index at which the specified element is to be inserted.element - element to be inserted.java.lang.ArrayIndexOutOfBoundsException - if index is out of range.public final int removeIndex(int index)
index - the index of the element to removed.java.lang.ArrayIndexOutOfBoundsException - if index is out of range.public final void clear()
public final boolean containsAll(int[] a)
a - array containing the elements to be tested for membership.public final boolean containsAll(IntArrayList v)
v - IntArrayList of elements to be tested for membership.public final boolean addAll(int[] a)
a - array containing the elements to be inserted.java.lang.ClassCastException - if the collection contains a non-number.public final boolean addAll(IntArrayList v)
v - the IntArrayList of elements to be added.public final boolean removeAll(int[] a)
a - array of elements to be removed.public final boolean removeAll(IntArrayList v)
v - the IntArrayList of elements to be removed.public final boolean removeAllFirst(int[] a)
a - array of elements to be removed.public final boolean removeAllFirst(IntArrayList v)
v - the IntArrayList of elements to be removed.public final boolean retainAll(IntArrayList v)
v - IntArrayList of elements to be retained.public final void addAll(int index,
int[] a)
index - index at which the specified element is to be inserted.a - array of elements to be inserted.java.lang.ArrayIndexOutOfBoundsException - if index is out of range.public final void addAll(int index,
IntArrayList v)
index - index where to insert the first elementv - IntArrayList to be inserted into this IntArrayList.java.lang.ArrayIndexOutOfBoundsException - if index is invalid.public final boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - the object to be compared for equality with this IntArrayList.public int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic void removeRange(int fromIndex,
int toIndex)
N.B. Note that this method is public, whereas - strangely enough, it is protected in the java.util.ArrayList API!
fromIndex - index of first element to be removed.toIndex - index after last element to be removed.public final void setIncrementFactor(float incrementFactor)
incrementFactor - a float that is between 1.1 and 5.0java.lang.IllegalArgumentException - if not between 1.1 and 5.0public final void clear(int index)
index - the index above which clearing takes effect