public class IntList
extends java.lang.Object
Class IntList
represents a list of integers.
Class IntList
supports a clear()
method, but it does not
support a remove()
method.
IntList
is not thread-safe.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_INIT_CAPACITY
The default initial capacity of an
IntList , which is 10. |
Constructor and Description |
---|
IntList()
Constructs an
IntList object with the default
initial capacity. |
IntList(int initCapacity)
Constructs an
IntList object with the specified
initial capacity. |
Modifier and Type | Method and Description |
---|---|
void |
add(int element)
Adds the specified integer to the end of this list.
|
void |
clear()
Removes all elements from this list.
|
int |
decrementAndGet(int index)
Decrements by one the element at the specified position in this list.
|
int |
get(int index)
Returns the element at the specified position in this list.
|
int |
getAndDecrement(int index)
Decrements by one the element at the specified position in this list.
|
int |
getAndIncrement(int index)
Increments by one the element at the specified position in this list.
|
int |
incrementAndGet(int index)
Increments by one the element at the specified position in this list.
|
boolean |
isEmpty()
Returns
true if this list has no elements, and returns
false otherwise. |
int |
set(int index,
int element)
Replaces the element at the specified position in this list with the
specified element.
|
int |
size()
Returns the number of elements in this list.
|
int[] |
toArray()
Returns an integer array containing the sequence of elements in this
list.
|
java.lang.String |
toString()
Returns
java.util.Arrays.toString(this.toArray()) |
public static final int DEFAULT_INIT_CAPACITY
IntList
, which is 10.public IntList()
IntList
object with the default
initial capacity.DEFAULT_INIT_CAPACITY
public IntList(int initCapacity)
IntList
object with the specified
initial capacity.initCapacity
- the initial capacity of this listjava.lang.IllegalArgumentException
- if initCapacity < 0
public int get(int index)
index
- the index of the element to be returnedjava.lang.IndexOutOfBoundsException
- if
index < 0 || index >= this.size()
public int set(int index, int element)
index
- the index of the element to be replacedelement
- the element to be stored at the specified position
in this listjava.lang.IndexOutOfBoundsException
- if
index < 0 || index >= this.size()
public int getAndIncrement(int index)
index
- the index of the element to be incrementedjava.lang.IndexOutOfBoundsException
- if
index < 0 || index >= this.size()
public int getAndDecrement(int index)
index
- the index of the element to be decrementedjava.lang.IndexOutOfBoundsException
- if
index < 0 || index >= this.size()
public int incrementAndGet(int index)
index
- the index of the element to be incrementedjava.lang.IndexOutOfBoundsException
- if
index < 0 || index >= this.size()
public int decrementAndGet(int index)
index
- the index of the element to be decrementedjava.lang.IndexOutOfBoundsException
- if
index < 0 || index >= this.size()
public int size()
public boolean isEmpty()
true
if this list has no elements, and returns
false
otherwise.true
if this list has no elementspublic int[] toArray()
public void add(int element)
element
- the integer to be added to the end of this listpublic void clear()
public java.lang.String toString()
java.util.Arrays.toString(this.toArray())
toString
in class java.lang.Object
java.util.Arrays.toString(this.toArray())