1. First list<e> set inheritance with Collection<e>, is an interface.
①collection (The collection frame is the JDK1.2 version appears)
②list: Is ordered, the elements can be duplicated, thinking that the collection system has an index.
The ArrayList and LinkedList classes that implement this interface are often used
③arraylist: The underlying data structure uses the array structure,
Features: Fast query, but slightly slower additions and deletions. Thread is out of sync
LinkedList: The underlying uses a linked list data structure.
Features: Deletion speed quickly, query slightly slow.
Vector: (The JDK1.0 version appears) The bottom layer is the array data structure, thread synchronization. Replaced by the ArrayList. (no longer necessary.)
2. Two ways to traverse the list:
public class Demo {public static void Main (string[] args) { arraylist<string> list = new Arraylist<strin G> (); List.add ("A"); List.add ("B"); List.add ("C"); System.out.println ("... The first traversal method: for traversal ... "); for (Object li:list) { System.out.println (LI); } System.out.println ("... The second way of traversal: Listiterator iterate ... "); Listiterator<string> it = List.listiterator (); while (It.hasnext ()) { Object obj = It.next (); System.out.println (obj);}}}
3. Use linklist to simulate a stack or queue data structure. i.e.: Stack: Advanced back out; queue: FIFO
Class duilie{ private linkedlist<object> link; Duilie () { link = new linkedlist<object> (); } public void Myadd (Object obj) { link.addfirst (obj); } Public Object MyGet () { return link.removelast ();//FIFO---to change to advanced, turn 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"); Dl.myadd ("Java02"); Dl.myadd ("java03"); Dl.myadd ("Java04"); while (!dl.isnull ()) { System.out.println (Dl.myget ());}}}
The above is first-out, if you want to change the advanced, then according to the code to write a change on it.
The above mentioned is the whole content of this article, I hope you can like.
A list collection in Java and its traversal