public class ArrayIntList extends Object
Modifier and Type | Field and Description |
---|---|
private int[] |
data |
static int |
DEFAULT_CAPACITY |
private int |
size |
Constructor and Description |
---|
ArrayIntList()
Initializes a new empty list with initial capacity of DEFAULT_CAPACITY integers.
|
ArrayIntList(int initialCapacity)
Initializes a new array list with initial capacity of initialCapacity integers.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int value)
Adds value to the end of the list.
|
void |
add(int index,
int value)
Inserts value into the list at index.
|
private void |
checkIndex(int index)
Checks if index is a valid index into this ArrayIntList.
|
int |
get(int index)
Returns the value at index.
|
private void |
grow(int requiredCapacity)
Grows the ArrayIntList to have room for *at least* requiredCapacity elements.
|
boolean |
isEmpty()
Returns true if list is empty, false otherwise.
|
void |
remove(int index)
Removes the value at the given index, shifting later values over.
|
void |
set(int index,
int value)
Stores value in index.
|
int |
size()
Returns the number of elements in the list.
|
String |
toString()
Returns a String representation of the list consisting of the elements
in order, separated by commas and enclosed in square brackets.
|
private int size
private int[] data
public static final int DEFAULT_CAPACITY
public ArrayIntList(int initialCapacity)
public ArrayIntList()
public void add(int value)
public void add(int index, int value)
public int get(int index)
public void set(int index, int value)
public void remove(int index)
public int size()
public boolean isEmpty()
public String toString()
private void grow(int requiredCapacity)
private void checkIndex(int index)