Constructor and Description |
---|
IntList(int initialCapacity)
Creates an int list with a specified initial capacity.
|
IntList(int[] array,
int initialSize)
Creates an int list with a specified initial array.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int value)
Appends a value to the end of this list, increasing its size by 1.
|
void |
clear()
Sets the size of this list to 0.
|
static IntList |
copy(IntList other,
int startIndex,
int length)
Makes a new int list by copying a range from a given int list.
|
static IntList |
copy(IntList other,
int startIndex,
int length,
int initialCapacity)
Makes a new int list by copying a range from a given int list.
|
int |
get(int index)
Gets the value in this list at a given index.
|
void |
set(int index,
int value)
Sets a value at a given index in this list.
|
void |
setSize(int newSize)
Adjusts the size of this int list.
|
int |
size() |
String |
toString() |
public IntList(int initialCapacity)
initialCapacity
- public static IntList copy(IntList other, int startIndex, int length)
other
- the list from which a range of values is to be copied into the new liststartIndex
- the index in other
at which to start copyinglength
- the number of values to copy from other
length
public static IntList copy(IntList other, int startIndex, int length, int initialCapacity)
other
- the list from which a range of values is to be copied into the new liststartIndex
- the index in other
at which to start copyinglength
- the number of values to copy from other
initialCapacity
- the initial capacity of the new int list (must be greater or equal to
length
)length
public int size()
public void add(int value)
value
- the value to appendpublic int get(int index)
index
- the index of the element to returnIndexOutOfBoundsException
- if index < 0 || index >= size()
public void clear()
public void set(int index, int value)
index
- the index of the element to updatevalue
- the new value of the elementIndexOutOfBoundsException
- if index < 0 || index >= size()
public void setSize(int newSize)
newSize < size()
, the size is changed to newSize
. If
newSize > size()
, sufficient 0 elements are added until
size() == newSize
.newSize
- the new size of this int list