Java-List source code analysis
List inherits from the Collection interface. List is also a Collection interface. List is an ordered queue. No element in the List will have an index. The index of the first element is 0, and the index values of the subsequent elements are plus 1 in sequence, repeated elements are allowed in the List. List Interface source code:
Public interface List
Extends Collection
{Int size (); // boolean isEmpty (); // determines whether it is null boolean contains (Object o); // determines whether it contains an Object Iterator
Iterator (); // returns the iteration Object [] toArray (); // returns the array of objects.
T [] toArray (T [] a); // Object array boolean add (E e); // add an Object boolean remove (Object o ); // delete an object boolean containsAll (Collection
C); // whether to include all objects of a Collection boolean addAll (Collection
C); // append the Collection object to the List boolean addAll (int index, Collection
C); // append the Collection object to the List boolean removeAll (Collection
C); // remove the object boolean retainAll (Collection
C); // remove the default void replaceAll (UnaryOperator
Operator) {Objects. requireNonNull (operator); final ListIterator
Li = this. listIterator (); while (li. hasNext () {li. set (operator. apply (li. next () ;}@ SuppressWarnings ({unchecked, rawtypes}) default void sort (Comparator
C) {Object [] a = this. toArray (); Arrays. sort (a, (Comparator) c); ListIterator
I = this. listIterator (); for (Object e: a) {I. next (); I. set (E) e) ;}} void clear (); // delete all objects boolean equals (Object o); // determine whether the two lists are the same int hashCode (); // return the hashCode E get (int index) of the List; // return the object E set (int index, E element) at a certain position ); // Replace the void add (int index, E element) object in a certain position; // add the object E remove (int index) in a certain position ); // Delete the int indexOf (Object o) Object at a certain position; // return the int lastIndexOf (Object o) position of an Object in the List; // ListIterator of the last Object in the List
ListIterator (); // returns the iterative ListIterator of the entire List
ListIterator (int index); // returns the List iteration List starting from a certain position.
SubList (int fromIndex, int toIndex); // capture part of the List @ Override default Spliterator
Spliterator () {return Spliterators. spliterator (this, Spliterator. ORDERED );}}