The List set is its traversal. The list set
1. First, List <E> Collection inheritance and Collection <E> is an interface.
① Collection (the Collection framework is JDK1.2)
② List: it is ordered, and elements can be repeated, so that the collection system has an index.
It is often used to implement the ArrayList and ArrayList classes of this interface.
③ Arraylist: the underlying data structure uses an array structure,
Feature: the query speed is fast, but the addition and deletion are slow. Thread not synchronized
Linked list: the bottom layer uses the Linked List data structure.
Features: Fast addition, deletion, and slow query.
Vector :( JDK1.0) the underlying layer is the array data structure, and the thread is synchronized. Replaced by ArrayList. (No more)
2. List traversal methods:
1 public class Demo {2 public static void main (String [] args) {3 ArrayList <String> list = new ArrayList <String> (); 4 list. add ("A"); 5 list. add ("B"); 6 list. add ("C"); 7 8 System. out. println ("........ the first Traversal method: for traversal ...... "); 9 for (Object li: list) {10 System. out. println (li); 11} 12 13 System. out. println ("........ the second Traversal method: ListIterator iterative traversal ...... "); 14 ListIterator <String> it = list. listIterator (); 15 while (it. hasNext () {16 Object obj = it. next (); 17 System. out. println (obj); 18} 19} 20}
:
3. Use LinkList to simulate a stack or queue data structure. Namely: Stack: first-in-first-out; queue: first-in-first-out
Class Duilie {private jsonlist <Object> link; Duilie () {link = new jsonlist <Object> ();} public void myAdd (Object obj) {link. addFirst (obj);} public Object myGet () {return link. removeLast (); // first-in-first-out --- if you want to change to first-out, change removelast () to removeFirst ()} public boolean isNull () {return link. isEmpty () ;}} public class Demo2 {public static void main (String [] args) {Duilie dl = new Duilie (); dl. myAdd ("java01"); d L. myAdd ("java02"); dl. myAdd ("java03"); dl. myAdd ("java04"); while (! Dl. isNull () {System. out. println (dl. myGet ());}}}
:
The above is the first-in-first-out mode. If you want to change it to the first-out mode, you can simply change it based on the code.