Java List详解 - TongtongLan/Java GitHub Wiki

有序集合(也称为序列)。这个接口的用户可以精确地控制每个元素插入到列表中的哪个位置。用户可以通过整数索引(列表中的位置)来访问元素,并搜索列表中的元素。

与集合不同,列表通常允许重复的元素。更正式地说,列表通常允许存在元素e1和e2,e1.equals(e2),并且它们通常允许多个null元素(如果它们完全允许空元素的话)。

Note that these operations may execute in time proportional to the index value for some implementations (the LinkedList class, for example). Thus, iterating over the elements in a list is typically preferable to indexing through it if the caller does not know the implementation.

The List interface provides a special iterator, called a ListIterator, that allows element insertion and replacement, and bidirectional access in addition to the normal operations that the Iterator interface provides. A method is provided to obtain a list iterator that starts at a specified position in the list.

ListIterator<E> listIterator();

ListIterator<E> listIterator(int index);

The List interface provides two methods to search for a specified object. From a performance standpoint, these methods should be used with caution. In many implementations they will perform costly linear searches.

int indexOf(Object o);

int indexOf(Object o);

The List interface provides two methods to efficiently insert and remove multiple elements at an arbitrary point in the list.

boolean addAll(Collection<? extends E> c);

boolean removeAll(Collection<?> c);