I. Introduction of ArrayList1.ArrayList Introduction
ArrayList it is the real implementation class of the list interface. It is also the real need to use collection container objects in our development.
The ArrayList class, which is the implementation of the list interface. Must have a corner mark. You can also store duplicate elements and use all the unique methods in the list interface. The ArrayList collection container, which uses a mutable array as a container for storing elements, is used at the bottom.
The above analysis ArrayList the underlying mutable array. This mutable array is also known as the structure (data structure) of the underlying data store of the ArrayList collection.
ArrayList uses a mutable array of its underlying:
it has a relatively low efficiency in adding and deleting. Queries are more efficient. ArrayList It is a collection container that appears JDK1.2. It does not guarantee the security of the data .
2. Introduction to the construction methods and methods of ArrayList
The methods in ArrayList all come from the collection and list interfaces.
ii. introduction of LinkedList
The list interface is implemented as a link listing. Implements all optional list operations, and allows all elements (including null).
In addition to implementing the list interface, theLinkedList class is also the get,remove , and insert at the beginning and end of the list Element provides a uniform naming method. These actions allow the link list to be used as a stack, queue , or double-ended queue .
LinkedList Collection It is the direct implementation class of the list interface. It implements all the methods in the collection and list interfaces.
Liknedlist sets the list of links it uses at the bottom:
LinkedList: The list structure used at the bottom of the collection, because the list has headers and tails, so new methods are redefined in the LinkedList collection, which are designed around the head and tail of the linked list:
AddFirst
AddLast
Removefirst
Removelast
GetFirst
GetLast
A linked list structure can accomplish some of the structure in a data structure:
Queue: FIFO, LIFO. Data that is first entered into the structure is first taken out. For example: queue up to buy tickets and train across caves.
Stack: Advanced post-out, LIFO. For example: Stack memory in the Java memory structure. Pistol Magazine.
1 //simulate a queue or stack data structure2 classqueue{3 4 //Define a LinkedList collection5 PrivateLinkedList list =NewLinkedList ();6 7 Public voidmyadd (Object obj) {8 List.addfirst (obj);9 }Ten One PublicObject MyGet () { A returnlist.removelast (); - } - the Public BooleanIsEmpty () { - returnList.isEmpty (); - } - + } - //Test Class + Public classLinkedListDemo2 { A Public Static voidMain (string[] args) { at -Queue q =NewQueue (); - -Q.myadd ("AAA"); -Q.myadd ("BBB"); -Q.myadd ("CCC"); inQ.myadd ("ddd"); - to while( !Q.isempty ()) { + System.out.println (Q.myget ()); - } the } *}
third, the list interface under the collection summary:
List: The collection container underneath it has a foot tag, which can be traversed using a corner mark or listiterator.
ArrayList: Its bottom layer is a variable array, adding and deleting slow, query fast. Not secure.
LinkedList: Its bottom line is the list structure, with head and tail, which can simulate a queue or stack data structure. Delete quickly, query slow. Not safe
Iv. Collection of Vetor1.Vector Introduction
The Vector collection is a collection container object that existed during its JDK1.0 period. In the JDK1.2, a collection system appears, and the vector becomes an implementation class under the list interface.
The bottom of the vector is also a mutable array, consistent with the ArrayList bottom. Vector it can be safe, because it is slow in what efficiency.
After the development of the vector can be seen directly as ArrayList to use it.
The method names in vectors are the primary methods of vectors, as long as they are related to element. The rest is implemented from the collection or list interface.
1 /*2 * Introduce the ancient vector collection3 */4 Public classVectordemo {5 Public Static voidMain (string[] args) {6 7 //To create a collection object8Vector v =NewVector ();9 TenV.addelement ("AAA"); OneV.addelement ("AAA"); AV.addelement ("abc")); -V.addelement ("CCC"); - the //Traverse - for(Enumeration en =v.elements (); en.hasmoreelements ();) { - System.out.println (En.nextelement ()); - } + - for(Iterator it =v.iterator (); It.hasnext ();) { + System.out.println (It.next ()); A } at } -}
Enumeration: It is the predecessor of iterator and can also traverse the collection container.
However, because its functionality and iterator are heavily duplicated, and the method name provided in iterator is shorter than the method names in enumeration.
In development we prefer to use iterator instead of using enumeration iteration sets.
JAVA Foundation--java API Collection Framework (other collection classes, collection principle) 15