Java-list Source Code Analysis

Source: Internet
Author: User
Tags addall

The list inherits from the collection interface, and list is one of the collections. List is an ordered queue, none of the elements in the list will have an index, the first element index is 0, and the index value of the subsequent element allows duplicate elements in sequence +1,list. List Interface Source code:
Public Interfacelist<E>extendscollection<E> {intsize();//Size    BooleanIsEmpty();//Determine if it is empty    Booleancontains(Object o);//Determine if an object is included    iterator<E>iterator();//Return Iteration Object    Object[]ToArray(); //Returns an array of objects    <T>T[]ToArray(T[] a);//Object array    BooleanAdd(EE;//Add an object    BooleanRemove(Object o);//Delete an object    BooleanContainsall(collection<?> c); //Whether to include all objects of a collection    BooleanAddAll(COLLECTION&LT;?extendsE> C);//Append the collection object to the list    BooleanAddAll(intIndex, collection<?extendsE> C);//Append Collection object to list in a certain location    BooleanRemoveAll(collection<?> c);//Remove the objects contained in the collection    BooleanRetainall(collection<?> c);//Remove objects that are not included in the collection    default voidReplaceAll(unaryoperator<E> operator) {objects.requirenonnull (operator);Finallistiterator<E> li = This. Listiterator (); while(Li.hasnext ()) {Li.set (Operator.apply (Li.next ()));        }    }@SuppressWarnings({"Unchecked", "Rawtypes"})default voidSort(COMPARATOR&LT;?SuperE> C) {object[] a = This. ToArray ();        Arrays.sort (A, (Comparator) c);        listiterator<E> i = This. Listiterator (); for(Object e:a) {i.next ();            I.set ((EE;        }    }voidClear();//Delete all objects    Booleanequals(Object o);//Determine if two lists are the same    inthashcode();//Return to List of Hashcode    EGet(intIndex;//Returns an object at a location    ESet(intIndex, EElement;//Replace an object at a location    voidAdd(intIndex, EElement;//Add an object in a location    ERemove(intIndex;//Delete an object at a location    intindexOf(Object o);//Returns the position of an object in the list    intlastIndexOf(Object o);coordinates of the last object in the//list    listiterator<E>Listiterator();//Returns an iteration of the entire list    listiterator<E>Listiterator(intIndex; //Returns an iteration of the list starting from a location    list<E>sublist(intFromIndex, intToindex);//Intercept part list    @Override    defaultspliterator<E>Spliterator() {returnSpliterators.spliterator (This ,spliterator.ordered);    }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java-list Source Code Analysis

Related Article

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.