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 | Description |
---|---|---|
static int |
DEFAULT_INIT_CAPACITY |
The default initial capacity of an
IntList , which is 16. |
Constructor | Description |
---|---|
IntList() |
Constructs an
IntList object with the default
initial capacity. |
IntList(int initCapacity) |
Constructs an
IntList object with the specified
initial capacity. |
IntList(int[] ia) |
Constructs an
IntList by cloning the specified array. |
IntList(IntList intList) |
Constructs an
IntList by copying the specified IntList . |
Modifier and Type | Method | Description |
---|---|---|
void |
add(int value) |
Adds the specified integer to the end of this list.
|
int |
binarySearch(int value) |
Returns an index associated with the specified value, or
(-insertionPoint - 1) if the value is not found. |
void |
clear() |
Removes all elements from this list.
|
int[] |
copyOf(int newLength) |
Copies and returns this list of integers, truncating or padding with 0
as necessary so that the copy has the specified length.
|
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 |
pop() |
Removes and returns the last entry of this list.
|
int |
set(int index,
int value) |
Replaces the element at the specified position in this list with the
specified element.
|
int |
size() |
Returns the number of elements in this list.
|
void |
sort() |
Sorts the elements of this list in increasing order
|
java.util.stream.IntStream |
stream() |
Returns an
IntStream containing the sequence 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()) |
void |
truncate(int newSize) |
Truncates this list of integer by removing all elements whose
index is greater than or equal to the specified size.
|
public static final int DEFAULT_INIT_CAPACITY
IntList
, which is 16.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 IntList(int[] ia)
IntList
by cloning the specified array.ia
- a list of integer valuesjava.lang.NullPointerException
- if ia == null
public IntList(IntList intList)
IntList
by copying the specified IntList
.intList
- a list of integer valuesjava.lang.NullPointerException
- if intList == null
public void add(int value)
value
- the integer to be added to the end of this listpublic int pop()
java.lang.IndexOutOfBoundsException
- if this.isEmpty() == true
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 value)
index
- the index of the element to be replacedvalue
- the value 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 void sort()
public int binarySearch(int value)
(-insertionPoint - 1)
if the value is not found. The returned
value is undefined if the list of integers is not sorted in
increasing order.value
- the value to be searched for(-insertionPoint - 1)
if the value is not foundpublic int[] copyOf(int newLength)
newLength
- the length of the returned arrayjava.lang.NegativeArraySizeException
- if newLength < 0
public void truncate(int newSize)
newSize
- the number of elements in the truncated listjava.lang.IllegalArgumentException
- if newSize < 0
public int[] toArray()
public java.util.stream.IntStream stream()
IntStream
containing the sequence of elements in this
list. The contract for this method is unspecified if this
list is modified during use of the returned stream.IntStream
containing the sequence of elements in 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())