public class IntList extends Object
Constructor and Description |
---|
IntList()
Constructs an empty list with the initial capacity of 10
|
IntList(int... values)
Constructs a list containing the elements of
values . |
IntList(int initialCapacity)
Constructs an empty list with the specified initial capacity.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(int element)
Appends the specified element to the end of this list.
|
boolean |
addAll(IntList list)
Appends the elements of the specified list to the end of this list.
|
boolean |
addAt(int index,
int element)
Add the element at the specified position in this list.
|
void |
clear()
The list will be empty after this call returns.
|
int |
get(int index)
Returns the element at the specified position in this list.
|
int |
getQuick(int index)
Returns the element at the specified position in this list without doing any bounds checking.
|
boolean |
isEmpty()
Returns true if this list contains no elements.
|
boolean |
remove(int value)
Removes the first occurrence of the specified element from this list,
if it is present.
|
void |
removeAt(int index)
Removes the element at the specified position in this list.
|
void |
removeRange(int fromIndex,
int toIndex)
Removes from this list all of the elements whose index is between
fromIndex , inclusive, and toIndex , exclusive. |
void |
replace(int index,
int element)
Replaces the element at the specified position in this list with
the specified element.
|
void |
replaceQuick(int index,
int element)
Replaces the element at the specified position in this list with
the specified element without doing any bounds checking.
|
int |
size()
Returns the number of elements in this list.
|
int[] |
toArray()
Returns an array containing all of the elements in this list
in proper sequence (from first to last element).
|
public IntList()
public IntList(int initialCapacity)
public IntList(int... values)
values
.values
- the values that are to be placed in this listpublic int size()
public boolean isEmpty()
public int get(int index)
index
- index of the element to returnIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())public int getQuick(int index)
index
- index of the element to returnpublic void replace(int index, int element)
index
- index of the element to replaceelement
- element to be stored at the specified positionIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())public void replaceQuick(int index, int element)
index
- index of the element to replaceelement
- element to be stored at the specified positionIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())public boolean add(int element)
element
- element to be appended to this listpublic boolean addAt(int index, int element)
index
- index of the element to putelement
- element to be stored at the specified positionpublic boolean addAll(IntList list)
list
- elements to be appended to this listpublic boolean remove(int value)
value
- element to be removed from this list, if presentpublic void removeAt(int index)
index
- the index of the element to be removedIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())public void removeRange(int fromIndex, int toIndex)
fromIndex
, inclusive, and toIndex
, exclusive.
Shifts any succeeding elements to the left (reduces their index).
This call shortens the list by (toIndex - fromIndex)
elements.
(If toIndex==fromIndex
, this operation has no effect.)IndexOutOfBoundsException
- if fromIndex
or
toIndex
is out of range
(fromIndex < 0 ||
fromIndex >= size() ||
toIndex > size() ||
toIndex < fromIndex
)public void clear()
public int[] toArray()
The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.
Copyright © 2018. All rights reserved.