public class DynamicIntArray
extends java.lang.Object
implements java.io.Serializable
java.util.ArrayList
, but specifically for
int
s. This is basically an array of integers that resizes
itself (if necessary) when adding new elements.构造器和说明 |
---|
DynamicIntArray()
Constructs a new array object with an initial capacity of 10.
|
DynamicIntArray(int initialCapacity)
Constructs a new array object with a given initial capacity.
|
DynamicIntArray(int[] intArray)
Constructs a new array object from the given int array.
|
限定符和类型 | 方法和说明 |
---|---|
void |
add(int value)
Appends the specified
int to the end of this array. |
void |
add(int index,
int value)
Inserts the specified
int at the specified position in
this array. |
void |
add(int index,
int[] intArray)
Inserts all
int s in the specified array into this array
object at the specified location. |
void |
clear()
Removes all values from this array object.
|
boolean |
contains(int integer)
Returns whether this array contains a given integer.
|
void |
decrement(int from,
int to)
Decrements all values in the array in the specified range.
|
void |
fill(int value)
Sets the value of all entries in this array to the specified value.
|
int |
get(int index)
Returns the
int at the specified position in this array
object. |
int |
getSize()
Returns the number of
int s in this array object. |
int |
getUnsafe(int index)
Returns the
int at the specified position in this array
object, without doing any bounds checking. |
void |
increment(int from,
int to)
Increments all values in the array in the specified range.
|
void |
insertRange(int offs,
int count,
int value) |
boolean |
isEmpty()
Returns whether or not this array object is empty.
|
void |
remove(int index)
Removes the
int at the specified location from this array
object. |
void |
removeRange(int fromIndex,
int toIndex)
Removes the
int s in the specified range from this array
object. |
void |
set(int index,
int value)
Sets the
int value at the specified position in this
array object. |
void |
setUnsafe(int index,
int value)
Sets the
int value at the specified position in this
array object, without doing any bounds checking. |
public DynamicIntArray()
public DynamicIntArray(int initialCapacity)
initialCapacity
- The initial capacity.java.lang.IllegalArgumentException
- If initialCapacity
is
negative.public DynamicIntArray(int[] intArray)
DynamicIntArray
will have an initial capacity of 110%
the size of the array.intArray
- Initial data for the array object.java.lang.NullPointerException
- If intArray
is
null
.public void add(int value)
int
to the end of this array.value
- The int
to be appended to this array.public void add(int index, int[] intArray)
int
s in the specified array into this array
object at the specified location. Shifts the int
currently at that position (if any) and any subsequent
int
s to the right (adds one to their indices).index
- The index at which the specified integer is to be
inserted.intArray
- The array of int
s to insert.java.lang.IndexOutOfBoundsException
- If index
is less than
zero or greater than getSize()
.java.lang.NullPointerException
- If intArray is
null.
public void add(int index, int value)
int
at the specified position in
this array. Shifts the int
currently at that position (if
any) and any subsequent int
s to the right (adds one to
their indices).index
- The index at which the specified integer is to be
inserted.value
- The int
to be inserted.java.lang.IndexOutOfBoundsException
- If index
is less than
zero or greater than getSize()
.public void clear()
public boolean contains(int integer)
integer
- The int
for which to search.public void decrement(int from, int to)
from
- The range start offset (inclusive).to
- The range end offset (exclusive).increment(int, int)
public void fill(int value)
value
- The new value for all elements in the array.public int get(int index)
int
at the specified position in this array
object.index
- The index of the int
to return.int
at the specified position in this array.java.lang.IndexOutOfBoundsException
- If index
is less than
zero or greater than or equal to getSize()
.public int getUnsafe(int index)
int
at the specified position in this array
object, without doing any bounds checking. You really should use
get(int)
instead of this method.index
- The index of the int
to return.int
at the specified position in this array.public int getSize()
int
s in this array object.int
s in this array object.public void increment(int from, int to)
from
- The range start offset (inclusive).to
- The range end offset (exclusive).decrement(int, int)
public void insertRange(int offs, int count, int value)
public boolean isEmpty()
public void remove(int index)
int
at the specified location from this array
object.index
- The index of the int
to remove.java.lang.IndexOutOfBoundsException
- If index
is less than
zero or greater than or equal to getSize()
.public void removeRange(int fromIndex, int toIndex)
int
s in the specified range from this array
object.fromIndex
- The index of the first int
to remove.toIndex
- The index AFTER the last int
to remove.java.lang.IndexOutOfBoundsException
- If either of fromIndex
or toIndex
is less than zero or greater than or
equal to getSize()
.public void set(int index, int value)
int
value at the specified position in this
array object.index
- The index of the int
to setvalue
- The value to set it to.java.lang.IndexOutOfBoundsException
- If index
is less than
zero or greater than or equal to getSize()
.public void setUnsafe(int index, int value)
int
value at the specified position in this
array object, without doing any bounds checking. You should use
set(int, int)
instead of this method.index
- The index of the int
to setvalue
- The value to set it to.