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