1. Collection is a top-level interface of the collection class, and its direct inheritance interfaces include List and Set.
Collection
|--List: Elements are ordered and elements can be repeated. Because the collection system has an index.
|--ArrayList: The underlying data structure uses an array structure. Features: The query speed is very fast. But the addition and deletion are a little slow. Threads are out of sync.
|--LinkedList: The data structure of the linked list used in the underlying layer. Features: The speed of addition and deletion is very fast, and the query is slightly slow. Threads are out of sync.
|--Vector: The underlying layer is an array data structure. Thread synchronization. Replaced by ArrayList. Because of the low efficiency.
|--Set: Elements are disordered and elements cannot be repeated.
List: A unique method. Any method that can operate angle markers is a unique method of this system.
increase:
add(index,element); addAll(index,Collection);
Delete: remove(index);
Change: set(index, element);
check:
get(index): subList(from,to); listIterator(); int indexOf(obj): Get the location of the specified element. ListIterator listIterator();
List collection unique iterator. ListIterator is a subinterface of Iterator.
During iteration, elements in a collection cannot be manipulated by the method of the collection object. Because a ConcurrentModificationException exception will occur.
Therefore, when iterator, you can only use the iterator to miss the operation elements, but the Iterator method is limited, and you can only judge, take out, and delete the elements.
If you want other operations such as adding, modifying, etc., you need to use its sub-interface, ListIterator. This interface can only be obtained through the listIterator method of the List collection.
Example code:
import java.util.*;class ListDemo { public static void sop(Object obj) { System.out.println(obj); } public static void method() { ArrayList al = new ArrayList(); //Add element al.add("java01"); al.add("java02"); al.add("java03"); sop("The original collection is: "+al); //Add elements at the specified location. al.add(1,"java09"); //Delete the element at the specified location. //al.remove(2); //Modify the element. //al.set(2,"java007"); //Get element through angle markers. sop("get(1):"+al.get(1)); sop(al); //Get all elements. for(int x=0; x<al.size(); x++) { System.out.println("al("+x+")="+al.get(x)); } Iterator it = al.iterator(); while(it.hasNext()) { sop("next:"+it.next()); } //Get the location of the object through indexOf. sop("index="+al.indexOf("java02")); List sub = al.subList(1,3); sop("sub="+sub); } public static void main(String[] args) { //Demo list iterator. ArrayList al = new ArrayList(); //Add element al.add("java01"); al.add("java02"); al.add("java03"); sop(al); ListIterator li = al.listIterator(); //sop("hasPrevious():"+li.hasPrevious()); while(li.hasNext()) { Object obj = li.next(); if(obj.equals("java02")) //li.add("java009"); li.set("java006"); } while(li.hasPrevious()) { sop("pre::"+li.previous()); } //sop("hasNext():"+li.hasNext()); //sop("hasPrevious():"+li.hasPrevious()); sop(al); /* // During the iteration process, prepare to add or delete elements. Iterator it = al.iterator(); while(it.hasNext()) { Object obj = it.next(); if(obj.equals("java02")) //al.add("java008"); it.remove();//Remove the reference of java02 from the collection. sop("obj="+obj); } sop(al); */ }}The above is a compilation of the information on the JAVA Collection interface. I hope it can help students who learn java.