LinkedList: Located under the Java.util package
1 LinkedList Overview
Features: The underlying data structure is linked list, adding and deleting fast query slow, non-synchronous, thread insecure, efficient, orderly (access order consistent), allow storage of duplicate values, allow the storage of null values, easy to implement stack, queue, two-way queue structure;
Common constructs:
Public LinkedList (): null parameter construct, build an empty list.
Common methods: Similar to ArrayList, only the unique functional methods are listed here.
1) Add Features:
Public AddFirst (e E): Inserts the specified element at the beginning of this list.
Public AddLast (e E): Inserts the specified element at the end of this list.
2) Get Features
Public E Element (): Gets the header (first element) of this list without removing it.
Public E GetFirst (): Returns the first element of this list.
Public E GetLast (): Returns the last element of this list.
3) Delete function
Public E Removefirst (): Removes and returns the first element of this list.
Public E Removelast (): Removes and returns the last element of this list.
4) There are stacks, queue-related functional methods ...
The LinkedList collection belongs to a subclass in the list collection, which uses a similar ArrayList.
2 LinkedList applications
1) Simulation stack structure : The bottom package LinkedList collection, realizes stack stack structure
Package collection.test;
Import java.util.LinkedList;
public class Mystack<t> {
Private linkedlist<t> list;
Public Mystack () {
List = new linkedlist<t> ();
}
Public boolean Add (T obj) {
List.addfirst (obj);
return true;
}
Public Object get () {
return List.removefirst ();
}
public Boolean isEmpty () {
return List.isEmpty ();
}
}
public class Mystacktest {
public static void Main (string[] args) {
mystack<string> stack = new mystack<string> ();
Press Stack
Stack.add ("Hello");
Stack.add ("World");
Stack.add ("Java");
Pop-up stack
while (!stack.isempty ()) {
System.out.println (Stack.get ());
}
}
}
LinkedList of the Java collection