The origin of the collection class:
Objects are used to encapsulate unique data, and objects need to be stored if the number of objects is indeterminate.
is stored using the collection container.
Set Features:
1. A container for storing objects.
2, the length of the set is variable.
3. The base data type value cannot be stored in the collection.
Collection container because of the internal data structure, there are a number of specific containers, constantly upward extraction, forming a set of framework .
The top layer of the frame is the Collection interface.
Common methods of collection:
1. Add
Boolean Add (Object obj);
Boolean AddAll (Collection coll);
2. Delete
Boolean remove (Object obj);
Boolean RemoveAll (Collection coll); Removes the same element from the two collection from the collection that calls RemoveAll.
void Clear (); Clear
3. Judgment
Boolean contains (Object obj);
Boolean Containsall (Collection coll);
Boolean isEmpty ();
4. Get
int size ();
Iterator Iterator (); The way to remove an element: an iterator.
The object must depend on the specific container, because each container has a different data structure.
So the iterator object is internally implemented in the container.
For a container user, a specific implementation is not important, as long as the object is obtained through the container to the iterator of the implementation, that is, the Interator method.
The object, similar to the clip in the Scratching Doll game machine .
The iterator interface is the common interface for extracting elements from all collection containers.
5. Other
Boolean Retainall (Collection coll); Takes the intersection, preserves the same elements as the specified collection, and removes the different elements. Contrary to the RemoveAll function.
Object[] ToArray (); Converts a collection to an array.
"Java Learning Notes" collection Framework Ⅰ