[Java learning notes] Collection framework I, java learning notes
Collection class:
An object is used to encapsulate special data. An object needs to be stored if the number of objects is uncertain.
The collection container is used for storage.
Set features:
1. the container used to store objects.
2. The length of the set is variable.
3. Basic data type values cannot be stored in a collection.
Because of the different internal data structures, a collection container has a variety of specific containers that are constantly extracted to form a collection framework.
The top layer of the Framework isCollectionInterface.
Common methods of Collection:
1. Add
Boolean add(E e)
;
BooleanaddAll(Collection<? extends E> c)
;
2. Delete
Boolean remove (Object obj );
BooleanremoveAll(Collection<?> c)
; // Delete the same elements from the two sets that call removeAll.
Void clear (); // clear
3. Judgment
Boolean contains (Object obj );
BooleancontainsAll(Collection<?> c)
;
Boolean isEmpty ();
4. Obtain
Int size ();
Iterator iterator (); // method of retrieving elements: Iterator.
This object must depend on a specific container because the data structure of each container is different.
Therefore, the iterator object is implemented internally in the container.
For container users, the specific implementation is not important. You only need to obtain the object of the implementation iterator through the container, that is, the interator method.
This object is similarCapture clips from doll game consoles.
The Iterator interface is a public interface for retrieving elements from all Collection containers.
5. Others
BooleanretainAll(Collection<?> c)
; // Take the intersection, retain the same elements of the specified set, and delete different elements. Unlike removeAll.
Object [] toArray (); // converts a set into an array.