| 构造器和说明 |
|---|
IntArrayList()
构建一个空的列表.
|
IntArrayList(int initialCapacity)
指定容量的方式构建一个IntList.
|
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
add(int e)
Appends the specified element to the end of this list.
|
boolean |
addAll(int[] a)
Appends all of the elements in the specified collection to the end of
this list, in the order that they are returned by the specified
collection's Iterator.
|
void |
clear()
Removes all of the elements from this list.
|
boolean |
contains(int o)
Returns true if this list contains the specified element.
|
boolean |
equals(java.lang.Object obj) |
void |
forEach(java.util.function.Consumer<? super java.lang.Integer> action) |
int |
get(int index)
Returns the element at the specified position in this list.
|
int |
hashCode() |
int |
indexOf(int o)
Returns the index of the first occurrence of the specified element in
this list, or -1 if this list does not contain the element.
|
boolean |
isEmpty()
Returns true if this list contains no elements.
|
int |
lastIndexOf(int x)
返回此列表中最后出现的指定元素的索引.
|
int |
random()
从列表中随机出一个元素.
|
boolean |
remove(int o)
Removes the first occurrence of the specified element from this list, if
it is present.
|
int |
size()
Returns the number of elements in this list.
|
int[] |
toArray()
返回按适当顺序包含列表中的所有元素的数组(从第一个元素到最后一个元素)。
|
void |
trimToSize()
将此IntArrayList实例的容量调整为列表的当前大小。
|
public IntArrayList()
public IntArrayList(int initialCapacity)
initialCapacity - 初始容量public void trimToSize()
应用程序可以使用此操作来最小化 IntArrayList实例的存储量。
public int size()
public boolean isEmpty()
public boolean contains(int o)
public int indexOf(int o)
public int lastIndexOf(int x)
如果列表不包含此元素,则返回 -1。
更确切地讲,返回满足 (get(i)==x) 的最高索引 i;
如果没有这样的索引,则返回 -1。
x - 要搜索的元素public int[] toArray()
由于此列表不维护对返回数组的任何引用,因而它将是“安全的”。(换句话说,即使数组支持此列表,此方法也必须分配一个新数组)。
因此, 调用者可以随意修改返回的数组。
public int get(int index)
index - index of the element to returnjava.lang.IndexOutOfBoundsExceptionpublic boolean add(int e)
public boolean remove(int o)
public void clear()
public boolean addAll(int[] a)
a - collection containing elements to be added to this listjava.lang.NullPointerException - if the specified collection is nullpublic int hashCode()
hashCode 在类中 java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals 在类中 java.lang.Objectpublic void forEach(java.util.function.Consumer<? super java.lang.Integer> action)