Type Parameters:类型参数:E-the type of elements in this list此列表中元素的类型
All Implemented Interfaces:所有实现的接口:Serializable,Cloneable,Iterable<E>,Collection<E>,List<E>,RandomAccess
Direct Known Subclasses:直接已知子类:AttributeList,RoleList,RoleUnresolvedList
List interface. List接口的可调整大小的数组实现。null. null。List interface, this class provides methods to manipulate the size of the array that is used internally to store the list. List接口外,此类还提供了一些方法来操作内部用于存储列表的数组的大小。Vector, except that it is unsynchronized.)Vector,只是不同步。)
The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. size、isEmpty、get、set、iterator和listIterator操作以固定时间运行。The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. add操作在摊销的固定时间内运行,即添加n个元素需要O(n)倍时间。All of the other operations run in linear time (roughly speaking). 所有其他操作都在线性时间内运行(粗略地说)。The constant factor is low compared to that for the 与LinkedList implementation. LinkedList实现相比,常数因子较低。
Each 每个ArrayList instance has a capacity. ArrayList实例都有一个容量。The capacity is the size of the array used to store the elements in the list. 容量是用于存储列表中元素的数组的大小。It is always at least as large as the list size. 它始终至少与列表大小一样大。As elements are added to an ArrayList, its capacity grows automatically. 当元素添加到ArrayList时,其容量会自动增长。The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost. 除了添加要素具有恒定的摊余时间成本这一事实之外,没有详细说明增长政策。
An application can increase the capacity of an 应用程序可以在使用ArrayList instance before adding a large number of elements using the ensureCapacity operation. ensureCapacity操作添加大量元素之前增加ArrayList实例的容量。This may reduce the amount of incremental reallocation. 这可能会减少增量重新分配的数量。
Note that this implementation is not synchronized.请注意,此实现是不同步的。
If multiple threads access an 如果多个线程同时访问ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. ArrayList实例,并且至少有一个线程在结构上修改该列表,则必须在外部对其进行同步。(A structural modification is any operation that adds or deletes one or more elements, or explicitly resizes the backing array; merely setting the value of an element is not a structural modification.) (结构修改是指添加或删除一个或多个元素,或明确调整支持数组大小的任何操作;仅设置元素的值不是结构修改。)This is typically accomplished by synchronizing on some object that naturally encapsulates the list. 这通常通过在自然封装列表的某个对象上进行同步来实现。If no such object exists, the list should be "wrapped" using the Collections.synchronizedList method. 如果不存在此类对象,则应使用Collections.synchronizedList方法“包装”列表。This is best done at creation time, to prevent accidental unsynchronized access to the list:最好在创建时执行此操作,以防止意外不同步地访问列表:
List list = Collections.synchronizedList(new ArrayList(...));
The iterators returned by this class's iterator and listIterator methods are fail-fast:此类的iterator方法和listIterator方法返回的迭代器是快速失败:
if the list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. 如果在创建迭代器后的任何时候,以迭代器自己的remove方法或add方法以外的任何方式对列表进行结构修改,迭代器将抛出ConcurrentModificationException。Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future. 因此,在面对并发修改时,迭代器会快速、干净地失败,而不是在将来的不确定时间冒着任意、不确定行为的风险。
Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. 请注意,无法保证迭代器的快速失效行为,因为一般来说,在存在非同步并发修改的情况下,不可能做出任何硬保证。Fail-fast iterators throw 快速失败迭代器会尽最大努力抛出ConcurrentModificationException on a best-effort basis. ConcurrentModificationException。Therefore, it would be wrong to write a program that depended on this exception for its correctness: 因此,编写依赖于此异常的正确性的程序是错误的:the fail-fast behavior of iterators should be used only to detect bugs.迭代器的快速失败行为应该只用于检测bug。
This class is a member of the Java Collections Framework.此类是Java集合框架的成员。
Since:始于:- 1.2
See Also:参阅:- Collection, List, LinkedList, Vector, Serialized Form
Field Summary字段摘要Fields declared in class java.util.AbstractList在java.util.AbstractList中声明的字段modCount-
Constructor Summary构造函数摘要Constructors构造函数Constructor构造函数Description描述Constructs an empty list with an initial capacity of ten.构造一个初始容量为10的空列表。ArrayList(int initialCapacity)Constructs an empty list with the specified initial capacity.构造具有指定初始容量的空列表。ArrayList(Collection<? extends E> c)Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.按照集合迭代器返回的顺序,构造包含指定集合元素的列表。 -
Method Summary方法摘要Modifier and Type修饰符和类型Method方法Description描述voidInserts the specified element at the specified position in this list.在此列表中的指定位置插入指定元素。booleanAppends the specified element to the end of this list.将指定的元素追加到此列表的末尾。booleanaddAll(int index, Collection<? extends E> c)Inserts all of the elements in the specified collection into this list, starting at the specified position.从指定位置开始,将指定集合中的所有元素插入此列表。booleanaddAll(Collection<? extends E> c)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.按照指定集合的迭代器返回的顺序,将指定集合中的所有元素追加到此列表的末尾。voidclear()Removes all of the elements from this list.从此列表中删除所有元素。clone()Returns a shallow copy of this返回此ArrayListinstance.ArrayList实例的浅层副本。booleanReturns如果此列表包含指定的元素,则返回trueif this list contains the specified element.true。voidensureCapacity(int minCapacity)Increases the capacity of this如有必要,请增加此ArrayListinstance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.ArrayList实例的容量,以确保它至少可以容纳最小容量参数指定的元素数。booleanCompares the specified object with this list for equality.比较指定对象与此列表是否相等。voidPerforms the given action for each element of the对Iterableuntil all elements have been processed or the action throws an exception.Iterable的每个元素执行给定的操作,直到所有元素都已处理或该操作引发异常为止。get(int index)Returns the element at the specified position in this list.返回此列表中指定位置的元素。inthashCode()Returns the hash code value for this list.返回此列表的哈希代码值。intReturns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.返回此列表中指定元素第一次出现的索引,如果此列表不包含该元素,则返回-1。booleanisEmpty()Returns如果此列表不包含任何元素,则返回trueif this list contains no elements.true。iterator()Returns an iterator over the elements in this list in proper sequence.按正确的顺序返回此列表中元素的迭代器。intlastIndexOf(Object o)Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.返回此列表中指定元素最后一次出现的索引,如果此列表不包含该元素,则返回-1。Returns a list iterator over the elements in this list (in proper sequence).返回此列表中元素的列表迭代器(按正确顺序)。listIterator(int index)Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.返回此列表中元素的列表迭代器(按正确顺序),从列表中的指定位置开始。remove(int index)Removes the element at the specified position in this list.删除此列表中指定位置的元素。booleanRemoves the first occurrence of the specified element from this list, if it is present.从该列表中删除指定元素的第一个匹配项(如果存在)。booleanremoveAll(Collection<?> c)Removes from this list all of its elements that are contained in the specified collection.从此列表中删除指定集合中包含的所有元素。booleanRemoves all of the elements of this collection that satisfy the given predicate.删除此集合中满足给定谓词的所有元素。protected voidremoveRange(int fromIndex, int toIndex)Removes from this list all of the elements whose index is between从此列表中删除其索引介于fromIndex, inclusive, andtoIndex, exclusive.fromIndex(包含)和toIndex(不含)之间的所有元素。booleanretainAll(Collection<?> c)Retains only the elements in this list that are contained in the specified collection.仅保留此列表中包含在指定集合中的元素。Replaces the element at the specified position in this list with the specified element.用指定的元素替换此列表中指定位置的元素。intsize()Returns the number of elements in this list.返回此列表中的元素数。Creates a late-binding and fail-fast Spliterator over the elements in this list.在此列表中的元素上创建后期绑定和快速失败拆分器。subList(int fromIndex, int toIndex)Returns a view of the portion of this list between the specified返回此列表中指定的fromIndex, inclusive, andtoIndex, exclusive.fromIndex(包含)和toIndex(不含)之间部分的视图。Object[]toArray()Returns an array containing all of the elements in this list in proper sequence (from first to last element).返回一个数组,该数组按正确顺序(从第一个元素到最后一个元素)包含此列表中的所有元素。<T> T[]toArray(T[] a)Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.返回一个数组,该数组按正确顺序(从第一个元素到最后一个元素)包含此列表中的所有元素;返回数组的运行时类型是指定数组的运行时类型。voidTrims the capacity of this将此ArrayListinstance to be the list's current size.ArrayList实例的容量修剪为列表的当前大小。Methods declared in class java.util.AbstractList在java.util.AbstractList类中声明的方法equals, hashCodeMethods declared in class java.util.AbstractCollection在java.util.AbstractCollection类中声明的方法containsAll, toStringMethods declared in interface java.util.Collection在java.util.Collection接口中声明的方法parallelStream, stream, toArrayMethods declared in interface java.util.List在java.util.List接口中声明的方法containsAll, replaceAll, sort
-
Constructor Details构造函数细节-
ArrayList
public ArrayList(int initialCapacity)Constructs an empty list with the specified initial capacity.构造具有指定初始容量的空列表。Parameters:参数:initialCapacity-the initial capacity of the list列表的初始容量Throws:抛出:IllegalArgumentException-if the specified initial capacity is negative如果指定的初始容量为负
-
ArrayList
public ArrayList()Constructs an empty list with an initial capacity of ten.构造一个初始容量为10的空列表。 -
ArrayList
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.按照集合迭代器返回的顺序,构造包含指定集合元素的列表。Parameters:参数:c-the collection whose elements are to be placed into this list要将其元素放入此列表的集合Throws:抛出:NullPointerException-if the specified collection is null如果指定的集合为null
-
-
Method Details方法详细信息-
trimToSize
public void trimToSize()Trims the capacity of this将此ArrayListinstance to be the list's current size.ArrayList实例的容量修剪为列表的当前大小。An application can use this operation to minimize the storage of an应用程序可以使用此操作最小化ArrayListinstance.ArrayList实例的存储。 -
ensureCapacity
public void ensureCapacity(int minCapacity)Increases the capacity of this如有必要,请增加此ArrayListinstance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.ArrayList实例的容量,以确保它至少可以容纳最小容量参数指定的元素数。Parameters:参数:minCapacity-the desired minimum capacity所需的最小容量
-
size
public int size()Returns the number of elements in this list.返回此列表中的元素数。 -
isEmpty
public boolean isEmpty()Returns如果此列表不包含任何元素,则返回trueif this list contains no elements.true。Specified by:指定者:isEmptyin interfaceCollection<E>Collection<E>接口中的isEmptySpecified by:指定者:isEmptyin interfaceList<E>List<E>接口中的isEmptyOverrides:覆盖:isEmptyin interfaceAbstractCollection<E>AbstractCollection<E>类中的isEmptyReturns:返回:如果此列表不包含任何元素,则为trueif this list contains no elementstrue
-
contains
Returns如果此列表包含指定的元素,则返回trueif this list contains the specified element.true。More formally, returns更正式地说,当且仅当此列表包含至少一个元素trueif and only if this list contains at least one elementesuch thatObjects.equals(o, e).e,使得Objects.equals(o, e)为true时,才返回true。Specified by:指定者:containsin interfaceCollection<E>Collection<E>接口中的containsSpecified by:指定者:containsin interfaceList<E>List<E>接口中的containsOverrides:覆盖:containsin interfaceAbstractCollection<E>AbstractCollection<E>类中的containsParameters:参数:o-element whose presence in this list is to be tested要测试其在该列表中的存在的元素Returns:返回:如果此列表包含指定的元素,则为trueif this list contains the specified elementtrue
-
indexOf
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.返回此列表中指定元素第一次出现的索引,如果此列表不包含该元素,则返回-1。More formally, returns the lowest index更正式地说,返回满足isuch thatObjects.equals(o, get(i)), or -1 if there is no such index.Objects.equals(o, get(i))的最低的索引i,如果没有这样的索引,则返回-1。Specified by:指定者:indexOfin interfaceList<E>List<E>接口中的indexOfOverrides:覆盖:indexOfin interfaceAbstractList<E>AbstractList<E>类中的indexOfParameters:参数:o-element to search for要搜索的元素Returns:返回:the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element此列表中指定元素第一次出现的索引,如果此列表不包含该元素,则为-1
-
lastIndexOf
Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.返回此列表中指定元素最后一次出现的索引,如果此列表不包含该元素,则返回-1。More formally, returns the highest index更正式地说,返回满足isuch thatObjects.equals(o, get(i)), or -1 if there is no such index.Objects.equals(o, get(i))的最高的索引i,如果没有这样的索引,则返回-1。Specified by:指定者:lastIndexOfin interfaceList<E>List<E>接口中的lastIndexOfOverrides:覆盖:lastIndexOfin interfaceAbstractList<E>AbstractList<E>类中的lastIndexOfParameters:参数:o-element to search for要搜索的元素Returns:返回:the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element此列表中指定元素最后一次出现的索引,如果此列表不包含该元素,则为-1
-
clone
Returns a shallow copy of this返回此ArrayListinstance.ArrayList实例的浅层副本。(The elements themselves are not copied.)(元素本身不会被复制。) -
toArray
Returns an array containing all of the elements in this list in proper sequence (from first to last element).返回一个数组,该数组按正确顺序(从第一个元素到最后一个元素)包含此列表中的所有元素。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.因此,调用者可以自由修改返回的数组。This method acts as bridge between array-based and collection-based APIs.此方法充当基于阵列和基于集合的API之间的桥梁。Specified by:指定者:toArrayin interfaceCollection<E>Collection<E>接口中的toArraySpecified by:指定者:toArrayin interfaceList<E>List<E>接口中的toArrayOverrides:覆盖:toArrayin interfaceAbstractCollection<E>AbstractCollection<E>类中的toArrayReturns:返回:an array containing all of the elements in this list in proper sequence按正确顺序包含此列表中所有元素的数组See Also:参阅:- Arrays.asList(Object[])
-
toArray
public <T> T[] toArray(T[] a)Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.返回一个数组,该数组按正确顺序(从第一个元素到最后一个元素)包含此列表中的所有元素;返回数组的运行时类型是指定数组的运行时类型。If the list fits in the specified array, it is returned therein.如果列表适合指定的数组,则返回其中。Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.否则,将使用指定数组的运行时类型和此列表的大小分配一个新数组。If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to如果列表适合指定的数组,且有空闲空间(即数组中的元素多于列表),则紧跟在集合结束后的数组中的元素将设置为null.null。(This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)(只有在调用者知道列表不包含任何空元素时,这才有助于确定列表的长度。)Specified by:指定者:toArrayin interfaceCollection<E>Collection<E>接口中的toArraySpecified by:指定者:toArrayin interfaceList<E>List<E>接口中的toArrayOverrides:覆盖:toArrayin interfaceAbstractCollection<E>AbstractCollection<E>类中的toArrayType Parameters:类型参数:T-the component type of the array to contain the collection要包含集合的数组的组件类型Parameters:参数:a-the array into which the elements of the list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.如果列表元素足够大,则列表元素将存储到的数组中;否则,将为此目的分配相同运行时类型的新数组。Returns:返回:an array containing the elements of the list包含列表元素的数组Throws:抛出:ArrayStoreException-if the runtime type of the specified array is not a supertype of the runtime type of every element in this list如果指定数组的运行时类型不是此列表中每个元素的运行时类型的超类型NullPointerException-if the specified array is null如果指定的数组为null
-
get
Returns the element at the specified position in this list.返回此列表中指定位置的元素。Specified by:指定者:getin interfaceList<E>List<E>接口中的getSpecified by:指定者:getin interfaceAbstractList<E>AbstractList<E>类中的getParameters:参数:index-index of the element to return要返回的元素的索引Returns:返回:the element at the specified position in this list此列表中指定位置的元素Throws:抛出:IndexOutOfBoundsException-if the index is out of range如果索引超出范围 (index < 0 || index >= size())
-
set
Replaces the element at the specified position in this list with the specified element.用指定的元素替换此列表中指定位置的元素。Specified by:指定者:setin interfaceList<E>List<E>接口中的setOverrides:覆盖:setin interfaceAbstractList<E>AbstractList<E>类中的setParameters:参数:index-index of the element to replace要替换的元素的索引element-element to be stored at the specified position要存储在指定位置的元素Returns:返回:the element previously at the specified position先前位于指定位置的元素Throws:抛出:IndexOutOfBoundsException-if the index is out of range如果索引超出范围 (index < 0 || index >= size())
-
add
Appends the specified element to the end of this list.将指定的元素追加到此列表的末尾。Specified by:指定者:addin interfaceCollection<E>Collection<E>接口中的addSpecified by:指定者:addin interfaceList<E>List<E>接口中的addOverrides:覆盖:addin interfaceAbstractList<E>AbstractList<E>类中的addParameters:参数:e-element to be appended to this list要附加到此列表的元素Returns:返回:true(as specified by Collection.add(E))(由Collection.add(E)指定)
-
add
Inserts the specified element at the specified position in this list.在此列表中的指定位置插入指定元素。Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).将当前位于该位置的元素(如果有)和任何后续元素向右移动(将一个元素添加到其索引中)。Specified by:指定者:addin interfaceList<E>List<E>接口中的addOverrides:覆盖:addin interfaceAbstractList<E>AbstractList<E>类中的addParameters:参数:index-index at which the specified element is to be inserted要插入指定元素的索引element-element to be inserted要插入的元素Throws:抛出:IndexOutOfBoundsException-if the index is out of range如果索引超出范围 (index < 0 || index > size())
-
remove
Removes the element at the specified position in this list.删除此列表中指定位置的元素。Shifts any subsequent elements to the left (subtracts one from their indices).将任何后续元素向左移动(从其索引中减去一个)。Specified by:指定者:removein interfaceList<E>List<E>接口中的removeOverrides:覆盖:removein interfaceAbstractList<E>AbstractList<E>类中的removeParameters:参数:index-the index of the element to be removed要删除的元素的索引Returns:返回:the element that was removed from the list从列表中删除的元素Throws:抛出:IndexOutOfBoundsException-if the index is out of range如果索引超出范围 (index < 0 || index >= size())
-
equals
Compares the specified object with this list for equality.比较指定对象与此列表是否相等。Returns当且仅当指定对象也是列表、两个列表的大小相同且两个列表中所有对应的元素对相等时,返回trueif and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal.true。(Two elements(如果e1ande2are equal if(e1==null ? e2==null : e1.equals(e2)).)(e1==null ? e2==null : e1.equals(e2)),则两个元素e1和e2相等。)In other words, two lists are defined to be equal if they contain the same elements in the same order.换句话说,如果两个列表包含相同顺序的相同元素,则它们被定义为相等。Specified by:指定者:equalsin interfaceCollection<E>Collection<E>接口中的equalsSpecified by:指定者:equalsin interfaceList<E>List<E>接口中的equalsOverrides:覆盖:equalsin interfaceAbstractList<E>AbstractList<E>类中的equalsParameters:参数:o-the object to be compared for equality with this list要比较的对象是否与此列表相等Returns:返回:如果指定的对象等于此列表,则为trueif the specified object is equal to this listtrueSee Also:参阅:- Object.hashCode(), HashMap
-
hashCode
public int hashCode()Returns the hash code value for this list.返回此列表的哈希代码值。Specified by:指定者:hashCodein interfaceCollection<E>Collection<E>接口中的hashCodeSpecified by:指定者:hashCodein interfaceList<E>List<E>接口中的hashCodeOverrides:覆盖:hashCodein interfaceAbstractList<E>AbstractList<E>类中的hashCodeReturns:返回:the hash code value for this list此列表的哈希代码值See Also:参阅:- Object.equals(java.lang.Object), System.identityHashCode(java.lang.Object)
-
remove
Removes the first occurrence of the specified element from this list, if it is present.从该列表中删除指定元素的第一个匹配项(如果存在)。If the list does not contain the element, it is unchanged.如果列表不包含该元素,则该列表将保持不变。More formally, removes the element with the lowest index更正式地说,删除索引isuch thatObjects.equals(o, get(i))(if such an element exists).i最低的元素,只要满足Objects.equals(o, get(i))(如果存在这样的元素)。Returns如果此列表包含指定的元素,则返回trueif this list contained the specified element (or equivalently, if this list changed as a result of the call).true(如果此列表因调用而更改,则返回等效值)。Specified by:指定者:removein interfaceCollection<E>Collection<E>接口中的removeSpecified by:指定者:removein interfaceList<E>List<E>接口中的removeOverrides:覆盖:removein interfaceAbstractCollection<E>AbstractCollection<E>类中的removeParameters:参数:o-element to be removed from this list, if present要从此列表中删除的元素(如果存在)Returns:返回:如果此列表包含指定的元素,则为trueif this list contained the specified elementtrue
-
clear
public void clear()Removes all of the elements from this list.从此列表中删除所有元素。The list will be empty after this call returns.此调用返回后,列表将为空。Specified by:指定者:clearin interfaceCollection<E>Collection<E>接口中的clearSpecified by:指定者:clearin interfaceList<E>List<E>接口中的clearOverrides:覆盖:clearin interfaceAbstractList<E>AbstractList<E>类中的clear
-
addAll
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.按照指定集合的迭代器返回的顺序,将指定集合中的所有元素追加到此列表的末尾。The behavior of this operation is undefined if the specified collection is modified while the operation is in progress.如果在操作进行过程中修改了指定的集合,则此操作的行为未定义。(This implies that the behavior of this call is undefined if the specified collection is this list, and this list is nonempty.)(这意味着,如果指定的集合是此列表,并且此列表为非空,则此调用的行为是未定义的。)Specified by:指定者:addAllin interfaceCollection<E>Collection<E>接口中的addAllSpecified by:指定者:addAllin interfaceList<E>List<E>接口中的addAllOverrides:覆盖:addAllin interfaceAbstractCollection<E>AbstractCollection<E>类中的addAllParameters:参数:c-collection containing elements to be added to this list包含要添加到此列表的元素的集合Returns:返回:如果此列表因调用而更改,则为trueif this list changed as a result of the calltrueThrows:抛出:NullPointerException-if the specified collection is null如果指定的集合为nullSee Also:参阅:- AbstractCollection.add(Object)
-
addAll
Inserts all of the elements in the specified collection into this list, starting at the specified position.从指定位置开始,将指定集合中的所有元素插入此列表。Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices).将当前位于该位置的元素(如果有)和任何后续元素向右移动(增加其索引)。The new elements will appear in the list in the order that they are returned by the specified collection's iterator.新元素将按指定集合的迭代器返回的顺序出现在列表中。Specified by:指定者:addAllin interfaceList<E>List<E>接口中的addAllOverrides:覆盖:addAllin interfaceAbstractList<E>AbstractList<E>类中的addAllParameters:参数:index-index at which to insert the first element from the specified collection从指定集合中插入第一个元素的索引c-collection containing elements to be added to this list包含要添加到此列表的元素的集合Returns:返回:如果此列表因调用而更改,则为trueif this list changed as a result of the calltrueThrows:抛出:IndexOutOfBoundsException-if the index is out of range如果索引超出范围 (index < 0 || index > size())NullPointerException-if the specified collection is null如果指定的集合为null
-
removeRange
protected void removeRange(int fromIndex, int toIndex)Removes from this list all of the elements whose index is between从此列表中删除其索引介于fromIndex, inclusive, andtoIndex, exclusive.fromIndex(包含)和toIndex(不含)之间的所有元素。Shifts any succeeding elements to the left (reduces their index).将任何后续元素向左移动(减少其索引)。This call shortens the list by此调用将列表缩短(toIndex - fromIndex)elements.(toIndex - fromIndex)个元素。(If(如果toIndex==fromIndex, this operation has no effect.)toIndex==fromIndex,则此操作将无效。)Overrides:覆盖:removeRangein interfaceAbstractList<E>AbstractList<E>类中的removeRangeParameters:参数:fromIndex-index of first element to be removed要删除的第一个元素的索引toIndex-index after last element to be removed要删除的最后一个元素后的索引Throws:抛出:IndexOutOfBoundsException-if如果fromIndexortoIndexis out of rangefromIndex或toIndex超出范围 (fromIndex < 0 || toIndex > size() || toIndex < fromIndex)
-
removeAll
Removes from this list all of its elements that are contained in the specified collection.从此列表中删除指定集合中包含的所有元素。Specified by:指定者:removeAllin interfaceCollection<E>Collection<E>接口中的removeAllSpecified by:指定者:removeAllin interfaceList<E>List<E>接口中的removeAllOverrides:覆盖:removeAllin interfaceAbstractCollection<E>AbstractCollection<E>类中的removeAllParameters:参数:c-collection containing elements to be removed from this list包含要从此列表中删除的元素的集合Returns:返回:如果此列表因调用而更改,则为trueif this list changed as a result of the calltrueThrows:抛出:ClassCastException-if the class of an element of this list is incompatible with the specified collection (optional)如果此列表元素的类与指定的集合不兼容(可选)NullPointerException-if this list contains a null element and the specified collection does not permit null elements (optional), or if the specified collection is null如果此列表包含null元素且指定的集合不允许null元素(可选),或者指定的集合为nullSee Also:参阅:- Collection.contains(Object)
-
retainAll
Retains only the elements in this list that are contained in the specified collection.仅保留此列表中包含在指定集合中的元素。In other words, removes from this list all of its elements that are not contained in the specified collection.换句话说,从该列表中删除指定集合中不包含的所有元素。Specified by:指定者:retainAllin interfaceCollection<E>Collection<E>接口中的retainAllSpecified by:指定者:retainAllin interfaceList<E>List<E>接口中的retainAllOverrides:覆盖:retainAllin interfaceAbstractCollection<E>AbstractCollection<E>类中的retainAllParameters:参数:c-collection containing elements to be retained in this list包含要保留在此列表中的元素的集合Returns:返回:如果此列表因调用而更改,则为trueif this list changed as a result of the calltrueThrows:抛出:ClassCastException-if the class of an element of this list is incompatible with the specified collection (optional)如果此列表元素的类与指定的集合不兼容(可选)NullPointerException-if this list contains a null element and the specified collection does not permit null elements (optional), or if the specified collection is null如果此列表包含null元素且指定的集合不允许null元素(可选),或者指定的集合为nullSee Also:参阅:- Collection.contains(Object)
-
listIterator
Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.返回此列表中元素的列表迭代器(按正确顺序),从列表中的指定位置开始。The specified index indicates the first element that would be returned by an initial call to next.指定的索引指示将由对next的初始调用返回的第一个元素。An initial call to previous would return the element with the specified index minus one.对previous的初始调用将返回指定索引为负1的元素。Specified by:指定者:listIteratorin interfaceList<E>List<E>接口中的listIteratorOverrides:覆盖:listIteratorin interfaceAbstractList<E>AbstractList<E>类中的listIteratorParameters:参数:index-index of the first element to be returned from the list iterator (by a call to next)从列表迭代器返回的第一个元素的索引(通过调用next)Returns:返回:a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list从列表中的指定位置开始,在此列表中元素上的列表迭代器(按正确顺序)Throws:抛出:IndexOutOfBoundsException-if the index is out of range如果索引超出范围 (index < 0 || index > size())
-
listIterator
Returns a list iterator over the elements in this list (in proper sequence).返回此列表中元素的列表迭代器(按正确顺序)。Specified by:指定者:listIteratorin interfaceList<E>List<E>接口中的listIteratorOverrides:覆盖:listIteratorin interfaceAbstractList<E>AbstractList<E>类中的listIteratorReturns:返回:a list iterator over the elements in this list (in proper sequence)此列表中元素的列表迭代器(按正确顺序)See Also:参阅:- listIterator(int)
-
iterator
Returns an iterator over the elements in this list in proper sequence.按正确的顺序返回此列表中元素的迭代器。Specified by:指定者:iteratorin interfaceCollection<E>Collection<E>接口中的iteratorSpecified by:指定者:iteratorin interfaceIterable<E>Iterable<E>接口中的iteratorSpecified by:指定者:iteratorin interfaceList<E>List<E>接口中的iteratorOverrides:覆盖:iteratorin interfaceAbstractList<E>AbstractList<E>类中的iteratorReturns:返回:an iterator over the elements in this list in proper sequence按正确顺序遍历此列表中元素的迭代器
-
subList
Returns a view of the portion of this list between the specified返回此列表中指定的fromIndex, inclusive, andtoIndex, exclusive.fromIndex(包含)和toIndex(不含)之间部分的视图。(If(如果fromIndexandtoIndexare equal, the returned list is empty.)fromIndex和toIndex相等,则返回的列表为空。)The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa.返回的列表由该列表支持,因此返回列表中的非结构性更改将反映在此列表中,反之亦然。The returned list supports all of the optional list operations.返回的列表支持所有可选的列表操作。This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays).此方法消除了显式范围操作的需要(通常存在于数组中)。Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list.通过传递子列表视图而不是整个列表,任何需要列表的操作都可以用作范围操作。For example, the following idiom removes a range of elements from a list:例如,以下习惯用法从列表中删除一系列元素:list.subList(from, to).clear();
Similar idioms may be constructed for indexOf(Object) and lastIndexOf(Object), and all of the algorithms in the Collections class can be applied to a subList.可以为indexOf(Object)和lastIndexOf(Object)构造类似的习惯用法,集合类中的所有算法都可以应用于子列表。The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list.如果支持列表(即,此列表)以任何方式(而不是通过返回的列表)进行结构修改,则此方法返回的列表的语义将变得未定义。(Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)(结构修改是指更改此列表的大小,或以其他方式干扰列表,使正在进行的迭代可能产生不正确的结果。)Specified by:指定者:subListin interfaceList<E>List<E>接口中的subListOverrides:覆盖:subListin interfaceAbstractList<E>AbstractList<E>类中的subListParameters:参数:fromIndex-low endpoint (inclusive) of the subList子列表的低端(包括)toIndex-high endpoint (exclusive) of the subList子列表的高端(不含)Returns:返回:a view of the specified range within this list此列表中指定范围的视图Throws:抛出:IndexOutOfBoundsException-if an endpoint index value is out of range如果端点索引值超出范围(fromIndex < 0 || toIndex > size)IllegalArgumentException-if the endpoint indices are out of order如果端点索引不符合顺序(fromIndex > toIndex)
-
forEach
Description copied from interface:描述复制自接口:IterablePerforms the given action for each element of the对Iterableuntil all elements have been processed or the action throws an exception.Iterable的每个元素执行给定的操作,直到所有元素都已处理或该操作引发异常为止。Actions are performed in the order of iteration, if that order is specified.如果指定了迭代顺序,则按迭代顺序执行操作。Exceptions thrown by the action are relayed to the caller.操作引发的异常将转发给调用方。The behavior of this method is unspecified if the action performs side-effects that modify the underlying source of elements, unless an overriding class has specified a concurrent modification policy.如果操作执行了修改元素的底层源的副作用,则此方法的行为未指定,除非重写类指定了并发修改策略。 -
spliterator
Creates a late-binding and fail-fast Spliterator over the elements in this list.在此列表中的元素上创建后期绑定和快速失败拆分器。TheSpliteratorreports Spliterator.SIZED, Spliterator.SUBSIZED, and Spliterator.ORDERED.Spliterator报告Spliterator.SIZED、Spliterator.SUBSIZED和Spliterator.ORDERED。Overriding implementations should document the reporting of additional characteristic values.覆盖实现应记录额外特征值的报告。Specified by:指定者:spliteratorin interfaceCollection<E>Collection<E>接口中的spliteratorSpecified by:指定者:spliteratorin interfaceIterable<E>Iterable<E>接口中的spliteratorSpecified by:指定者:spliteratorin interfaceList<E>List<E>接口中的spliteratorReturns:返回:a此列表中元素上的Spliteratorover the elements in this listSpliteratorSince:始于:- 1.8
-
removeIf
Description copied from interface:描述复制自接口:CollectionRemoves all of the elements of this collection that satisfy the given predicate.删除此集合中满足给定谓词的所有元素。Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller.迭代期间或谓词引发的错误或运行时异常将转发给调用方。Specified by:指定者:removeIfin interfaceCollection<E>Collection<E>接口中的removeIfParameters:参数:filter-a predicate which returns为要删除的元素返回truefor elements to be removedtrue的谓词Returns:返回:如果删除了任何元素,则为trueif any elements were removedtrueThrows:抛出:NullPointerException-if the specified filter is null如果指定的筛选器为null
-