Java basic review: List Interface

Source: Internet
Author: User

Features of list:

(1) List has an ordered set, and each element in the SET has a corresponding sequence.

(2) duplicate elements can be used in the list set and corresponding elements can be accessed through indexes.

Import Java. util. arraylist; import Java. util. list; import Java. util. listiterator; public class listdemo {public static void main (string [] ARGs) {list = new arraylist (); list. add ("well"); list. add ("Tom"); list. add ("Lily"); system. out. println (list); // object get (INT index) returns the element at the specified position in the list. System. out. println (list. get (2); list. add ("well"); list. add ("Tom");/** int indexof (Object O) returns the index of the specified element that appears for the first time in this list. If this list does not contain this element, -1 is returned. * Lastindexof (Object O) returns the index of the last specified element in this list. If the list does not contain this element,-1 is returned. */System. out. println (list. indexof ("well"); // 0system. out. println (list. lastindexof ("Tom"); // 4/** object remove (INT index) removes the elements at the specified position in the list (optional ). , Returns the deleted object Boolean * Boolean remove (Object O) from the list to remove the specified element that appears for the first time (if any) (optional) * object set (INT index, object element) replace the specified position in the list with the specified Element (optional ). * Listiterator <E> listiterator () returns the list iterator of the list elements (in the appropriate order ). */For (listiterator <string> li = List. listiterator (); Li. hasnext ();) {system. Out. println (Li. Next ());}}}

 

Listiterator () method. This method returns the listiterator object. It inherits the iterator interface and provides a list-specific method.

Listiterator has the following special methods:

Boolean hasprevious () returns whether the iterator associated with the set has the previous element.

Object previous () returns the previous element of the iterator

 

Common classes in the list interface: (basic data structure)

Arraylist: sequence table. The thread is not secure and the query speed is fast.

Slow list: single-chain table, fast addition/Deletion

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.