Java----data Structure and Algorithm----JavaAPI:java.util.List interface

Source: Internet
Author: User

    •   
    • Java.util.List interface
    • /** * @author LXRM * @date 20170307 * @description This program describes the use of Java.util.List interface * java.util.List * overview: * 1) List interface is Colle Ction interface, So the list interface has all the member functions defined by the collection interface * In addition to all functions defined in its parent interface collection, the list interface adds its own function so that the list collection has its own Features * The newly added functions in the list interface are: A) The member function that is used to access the collection element according to the index * B) to return the members of the Listiterator object (Collect The ion interface defines a function that returns a iterator object, which, in addition to the iterator object, can be obtained Listiterator object and can traverse the LIS in more ways T Collection Element) * 2) The list collection allows repeating elements * 3) the elements in the list collection are in a certain order, and the order of the elements in the collection is the order in which each element is inserted * 4) The list collection allows you to access the collection using an index The elements in the * constructor: * the Java language interface does not have constructors * member Functions: * "1" overview, because list is an interface, so all of the following functions are not function body, There is no actual block of code * and since the list interface inherits the Java.util.Collection interface, the list interface contains all the functions defined by the collection interface * below All listed are functions in the list interface, unless otherwise specified, the corresponding functions are inherited from the collection interface * plus the "list interface new add function" labeled, is the list interface based on the list of the new member functions added to the feature, with the        To highlight the featured features of the list collection *         "2" int size ();//returns The number of elements in the collection, if the number of elements is >integer.max_value, then the return value of the function ==integer.max_value * "3" Boolean I Sempty ();//whether The collection is empty * "4" Boolean contains (Object O);//whether the collection contains elements O:object * "5" ITERATOR&LT;E&G T Iterator ();//returns an iterator that iterates through all the elements in the collection (that is, the iterator Object) * "list interface new add function" "5.1" listiterator<e> listiterator ();// Returns a Listiterator object that is more appropriate than iterator to traverse the list collection * "list interface new add function" "5.2" listiterator<e> listiterator (int Index);//and                                     The function function in "5.1" is similar, *//only the next pointer of the listiterator returned by this function has been referred to the index:int position in the list collection * After a initial call to {@linkListiterator#next next} will return the element of the index position in the list collection *//an initial call to {@linklistiterator#previous previous} will return the element on the index-1 position in the list collection * "6" object[] ToArray ();//transform The collection into an array * "7" <T> t[] toArray (t[] a);//this function is similar to the function given in "6", but this function has an additional function * function: this function, in addition to converting a set to an array of                             Outer * Also implements the conversion of the collection element data type to the array element data type (the data type represented by transforming the collection element from the original data type to the parameter of the cost function A:t[]--t) * In addition, the length of the return value of the function is specified (the length of the return value is consistent with the length of the parameter array of the function A:t[]) *@return The contents of the return value (array)--the data type of the array element in the return value--consistent with the parameter data type of the function * return value (array) Length--and this letter The length of the parameter array of the number is consistent, when the number of collection elements is less than the parameter array a:t[] length, null fills the empty space so that the return value length reaches the required * "8" Boolean add (e e);//add a new element to the collection and add the new element to the end of the list                 * "9" Boolean Remove (Object o);//delete an element from the collection (delete the first o:object in the list collection, the parameter element that corresponds to the smallest set subscript O:object) * "10" Boolean Containsall (collection<?> c);//determines whether the collection contains all elements in the parameter collection * "11" boolean AddAll (collection< ? Extends e> c);//append all elements in the parameter collection to the end of the collection (equivalent to the Set) * "list interface new Add function" "11.2" boolean addall (int index, collection<? extends E> c);//this function is similar to the function in "11", except that the function in *//"11" appends the parameter collection to the end of the collection, and this function appends the parameter collection The position of the index:int beginning of the collection is * "12" boolean removeall (collection<?> c);//after This function is executed, the collection will no longer contain any of the elements in the parameter collection (equivalent to the set phase Minus) * "13" boolean retainall (collection<?> c);//after executing this function, it will not be possible to include elements that do not exist in the parameter collection (equivalent to fetch Intersection) * "new add function for list interface" "13.1" list<e> SublisT (int fromIndex, int toindex);//returns A subset of the list collection (left and not included) * "14" void Clear ();//after executing the function, the collection will become empty *                                                 "15" boolean equals (Object O);//parameter O:object is also a collection that is used to determine whether the contents of the two collection are the same *                     (when and only if the two elements are the same type, the size is the same, and the element returns the same value sequentially) * "16" int hashcode ();//returns the hashcode code corresponding to the collection *  Note: if the contents of the two collections are identical, then the hashcode codes for the two collections must be identical * i.e., if a.equals (b) ==true, Then there must be A.hashcode () ==b.hashcode () * The Hashcode code of the collection is calculated according to the following formula * * <pre> * int hashcode =                     1;                     * For (E e:list) * hashcode = 31*hashcode + (e==null? 0:e.hashcode ()); * </pre> * "list interface new Add function" "17" e get (int index);//returns the element at a specific position of the list collection * "list interface new Add function" "18" e set (int index, e element);//replace The element at a particular position in the list collection * "list interface new add function" "19" void add (int index, E element);//add A new element element:e at a particular index of the list collection and move the corresponding element in the collection back * " List interface new Add function"20" E Remove (int index);//deletes The element at a particular position in the list collection and returns the deleted element as the return value, and also moves the element after index:int in the collection to the left * "list interface new add function" "21" int IndexOf (object O);//returns The position subscript for the first occurrence of o:object in the list collection, and returns 1 * "list interface new add function" "22" int lastIndexOf (Object O) If no element is present in the list collection;//                             Returns the position of the last occurrence of o:object in the list collection, or 1 * "list interface new Add function" "23" * "list interface new Add function" "24" * "list interface new Add function" "25" If there is no element in the list collection                  **/ packagejavaapi_datastructure;Importjava.util.ArrayList;Importjava.util.Collection;Importjava.util.List;Importjava.util.ListIterator; public classJavaapi_list { public Static voidmain (string[] Args) {list list=NewArrayList (); }}

Java----data Structure and Algorithm----JavaAPI:java.util.List interface

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.