One, List 1.List set unique features
/* * Unique features of the list collection: * A: Add function * void Add (int index,object Element): Add elements at specified location * B: Get function * Object get (int index): Gets the element at the specified position * C: Column Table iterator * Listiterator listiterator (): List collection-specific iterator * D: Delete Function * Object Remove (int index): delete element according to index, return deleted element * E: Modify function * Object SE T (int index,object Element): Modifies the element according to the index, returning the decorated element */
Test class
@Testpublic void Testlist () {List List = new ArrayList (), List.add ("AAA"), List.add ("BBB"), List.add ("CCC"), List.add (" DDD "); SYSTEM.OUT.PRINTLN (list);//1. add element List.add (1, "QQQ") at the specified index location; SYSTEM.OUT.PRINTLN (list)//2. Gets the element at the specified index position String str = (string) list.get (1); System.out.println ("element with index 1:" + str);//3. Removes the element list.remove (1) at the specified index position; SYSTEM.OUT.PRINTLN (list);//4. Modifies the element list.set (0, "KKK") at the specified index position; SYSTEM.OUT.PRINTLN (list);//5. List iterator Listiterator it = List.listiterator (); while (It.hasnext ()) {string s = (string) It.next (); System.out.print (S + "");} System.out.println ("");//Can be traversed backwards, but must first be traversed, meaningless while (it.hasprevious ()) {String s = (string) it.previous (); System.out.print (S + "");}}
Results:
[AAA, BBB, CCC, DDD]
[AAA, QQQ, BBB, CCC, DDD]
element with index 1: QQQ
[AAA, BBB, CCC, DDD]
[KKK, BBB, CCC, DDD]
KKK BBB CCC DDD
DDD CCC BBB KKK
Features of the 2.List sub-class
ArrayList
The underlying data structure is an array , query fast, and delete slowly .
threads are unsafe and highly efficient.
Vector
The underlying data structure is an array , query fast, and delete slowly .
thread-safe, low-efficiency.
LinkedList
The underlying data structure is linked list , query slow, delete quickly .
Threads are unsafe and highly efficient.
Second, ArrayList
1.ArrayList Introduction
ArrayList is a dynamic array whose capacity can grow dynamically.
It inherits from the Abstractlist, implements the list, randomaccess, cloneable, serializable these interfaces.
(1) ArrayList inherits from Abstractlist and implements the list. It is an array queue that provides related additions, deletions, modifications, and traversal functions.
(2) The ArrayList implements the Randomaccess interface and provides a random access function. In ArrayList, we can quickly get the element object through the element's serial number, which is fast random access.
(3) ArrayList implements the Cloneable interface, which covers the function clone () and can be cloned.
(4) The ArrayList implements the serializable interface, meaning that the ArrayList supports serialization and can be transmitted by serialization.
2. Constructors
Basic Java Learning (vi)-list