Collection
|--list: The elements are ordered and repeatable because the set system has an index
|--arraylist: The underlying data structure uses an array structure to query fast threads that are out of sync.
|--linkedlist: The underlying use of the linked list data structure deletion speed quickly query slightly slower.
|--vector: The underlying data structure uses the array-structured thread synchronization, which is replaced by the ArrayList.
|--set: Elements unordered, non-repeatable
List:
Unique method. Any method that can operate the table is the unique method of the system.
Increase
Add (index,element);
AddAll (index,collection);
Delete
Remove (index);
Change
Set (index,element);
Check
Get (index);
Sublist (from,to);
Listiterator ();
Suppose ArrayList al = new ArrayList ();
Get all elements
for (int x = 0,x<al.size (), x + +)//list collection without the Length property
{
System.out.println (Al.get (x));
}
Listiterator
List iterators
An iterator that is unique to the list collection. Listiterator is a sub-interface of iterator
The elements in the collection cannot be manipulated by the method of the collection object during the iteration, because a concurrency modification exception occurs (concurrentmodificationexception)
So when iterating, the elements can only be manipulated using iterators, but the iterator method is limited
Only elements can be judged, taken out, deleted by the operation
If you want other operations such as adding, modifying, you need its sub-interface Listiterator
This interface can only be obtained through the Listiterator method of the list collection.
/*
Iterator it = Al.iterator
while (It.hasnext ())
{
System.out.println (It.next ());
Object obj = It.next ();
if (Obj.equlas ("Java"))
al.add("Java01") at this point, both iterators and collections can operate on the reference-concurrent access (multiple operations cannot be performed on the same element)
It.remove () When printing, the obj element is not changed, the "Java" in the Al container is deleted, the Javac reference is removed from the collection, but obj is used, so it can be printed
System.out.println (obj);
}
System.out.println (AL);
/*
Listiterator Li = al. Listiterator ();
while (Li.hasnext ())
{
Object obj = Li.next ();
if (Obj.equlas ("Java"))
Li.add ("java02"); Compare with green font above
}
LinkedList
Unique methods:
AddFirst ();//Put elements on the first other bit and then move back
AddLast ();
GetFirst ();////gets the element without deleting it
GetLast ();
Removefirst ();//get element and delete
Removelast ();
Remove if the list is empty run out nosuchelementexception
So the general use
Offerfirst ();
Offerlast ();
Addfirst/addlast return type is void and Offerfirst/offerlast return type is Boolean
If the container length is exceeded when inserting in a finite container, the former throws an exception and the latter returns false
Peekfirst ();
Peeklast ();
Get element not deleted if no element returns null
Pollfirst ();
Polllast ();
Gets the element and removes it if there is no element, returns null
LinkedList link = new LinkedList
Colletion Learning-01