1. First of all, the collection inheritance with the collection <E> is an interface.
① Collection (the collection framework appears in JDK 1.2)
② List: It is orderly, and the element can be repeated, thinking that the collection system has indexes.
What is often used is the ArrayList and LinkedList classes that implement the interface
③ ArrayList: The underlying data structure uses an array structure,
Features: The query speed is fast, but the addition and deletion is slightly slower. Synchronous thread
LinkedList: The bottom layer uses the linked data structure.
Features: The increase and deletion speed is fast, and the query is slightly slower.
Vector: (JDK 1.0 appeared) at the bottom layer is the array data structure, thread synchronization. Replaced by ArrayList. (No more)
2. Two ways to traverse the list:
Public Class Demo {Public Static Void Main (String [] Args) {ArrayList <string> List = New ArrayList <string> (); list.add ("A"); list.add ("B"); list. ADD ("C"); System.out.println ("....... The first traversal method: for traversing ..."); for (object li: list) {systemm.out. Println (li);} System.out.println ("........ The second traversal method: Listitrator iteration ..."); listiterator <string> it = list.listIterator () ; about (it.hasnext ()) {object obj = it.next (); system.out.println (obj);}}}
Effect map:
3. Use LinkList to simulate a stack or queue data structure. That is: stack: advanced afterwards; queue: advanced first out
Class Duilie {Private LinkedList <Object> Link; Duilie () {link = New LINKEDList <Object> ();} Public Void MyAdd (Object Obj) ;} Public object myget () {Return link. Removelast (); // Advanced first-to be changed to advanced and then out, change the remains () to remainfired ()} public boyan isnull () {Return link.isempty ();} public class demo2 {pu2 {pu2 {PU block 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 ());}}}
Effect map:
The above is an advanced first. If you want to change it to the advanced, you can change it according to the code.
The above is all the contents of this article. I hope everyone can like it.