Java-List source code analysis

Source: Internet
Author: User

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 );}}
           
          
         
        
       
      
     
    
   
  
 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.