I. Overview of the collection
1. Common features in Collection
Boolean Add (Object e): Adding elements to the collection
void Clear (): empties all elements in the collection
Boolean contains (Object O): Determines whether an element is contained in the collection
Boolean IsEmpty (): Determines whether the elements in the collection are empty
Boolean remove (Object o): Deletes an element based on the content of the element
int size (): Gets the length of the collection
Object[] ToArray (): Ability to convert collections into arrays and store elements in the collection
2. iterators
There are a number of collections in Java that are stored differently when storing elements. We're going to take out the elements in these collections, which can be done in a common way.
Collection The general acquisition of the elements of the collection: before taking the element to determine whether there are any elements in the set, if there is, take this element out, continue to judge, if there is another out. All the elements in the collection have been taken out all the time. This method of extraction is known as an iterative term.
This method of fetching elements in the collection is described in the The iterator interface. The common methods of iterator interface are as follows
Hasnext () Method: Determine if there are elements in the set that can iterate
Next () method: Used to return the next element of the iteration and move the pointer back one bit.
3. Concurrency modification Exceptions
When iterating through the collection using iterators, the increment /Delete method in the collection is used, causing the concurrency modification exception to occur
Concurrency Modification Exception Resolution:
A: You can use the collection method to increment or delete a loop without using an iterator to traverse the collection
B: Iterator traversal is still used, then you need to use iterator's subinterface listiterator to implement adding to the collection
java--Collection