Interface-Oriented Programming:
Interface type variable =new implementation class ();
List list=new ArrayList ();
---------------------------------------
Characteristics and performance analysis of List implementation class
--------------------------------------
The common characteristics of the three and the following norms:
1): Allow element repetition;
2): Record the order in which elements are added successively
--------------------------------------
Vector class:
The bottom of the array structure algorithm, methods are used synchronized decoration, thread safety, but the equivalent of ArrayList lower;
ArrayList class:
The bottom layer has an array structure algorithm, the method does not use synchronized decoration, thread is unsafe, the equivalent of vector higher.
Arraylis now basically has replaced the status of Vector.
To ensure Arraylist thread safety, List lsit =collections.synchronizedlist (New Arraylist (...));
linklist class:
The underlying only has a doubly linked list structure algorithm, the method does not use synchronized adornment, thread is unsafe.
The performance problems of array structure algorithm and doubly linked list structure algorithm:
Array structure algorithm: Low insertion and deletion operations, high query and change;
Linked list structure algorithm: Insert and delete operation is fast, query and change is slow;
---------------------------------------------------------------------------
Use the selection:
Vector class Kill no use! Even if you want to use it, use the ArrayList class.
If the insert and delete operations are frequent, the Linklist class should be used;
If the query and change operations are frequent, the ArrayList class should be used;
In the development. More use of ArrayList class, according to the specific needs of the environment to choose;
Public Static voidMain (string[] args) {List List=NewArrayList (); List.add ("B"); List.add (C); List.add ("D"); List.add (E); //mode 1:for Cycle for(intindex = 0; Index < list.size (); index++) {Object rest= List.get (index);//removes the element at the specified index positionSystem.out.println (rest); } System.out.println ("---------------------------------------------------------------------------"); //mode 2:for-each enhanced for loop for(Object ele:list) {System.out.println (ele); } System.out.println ("---------------------------------------------------------------------------"); //Method 3: Use the while loop to manipulate the iterator iteratorIterator it=List.iterator (); while(It.hasnext ()) {System.out.println (It.next ()); } System.out.println ("---------------------------------------------------------------------------"); //Method 4: Use the For loop to manipulate the iterator iterator for(Iterator it2=list.iterator (); It2.hasnext ();) {System.out.println (It2.next ()); } System.out.println (list);}
---refactoring design of the Java Collection framework