1. First list<e> set inheritance and Collection<e>, is an interface.
①collection (The collection framework appears as a JDK1.2 version)
②list: Is ordered, elements can be repeated, thinking that the set system has an index.
The ArrayList and LinkedList classes that implement the interface are often used
③arraylist: The underlying data structures use an array structure,
Features: Query speed quickly, but added or deleted slightly slower. Thread is not synchronized
LinkedList: The underlying use is the linked list data structure.
Features: Adding and deleting speed quickly, query slightly slow.
Vector: (JDK1.0 version appears) the underlying is the array data structure, thread synchronization. was replaced by ArrayList. (No more)
2. List two ways to traverse:
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 iterative traversal ... ");
Listiterator<string> it = List.listiterator ();
while (It.hasnext ()) {
Object obj = It.next ();
System.out.println (obj);}}
Effect Chart:
3. Use linklist to simulate a stack or queue data structure. That is: stack: Advanced out; queue: Advanced First Out
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 ();//Advanced First out---to be replaced by Advanced, 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 ());
}
}}
Effect Chart:
Above for advanced first out, if you want to replace the advanced, then according to the code written in the change can be
The above mentioned is the entire content of this article, I hope you can enjoy.