Collection framework Introduction
Java Collection framework
Collection framework:
① The so-called framework is a collection of class libraries. A collection framework is a unified architecture used to represent and operate a set. It contains interfaces and classes that implement a set;
② Different collection classes in the Collection framework have different data structures. Therefore, you must select different collection classes based on application performance requirements during use;
③ Collection classes are stored in the java. util package. During programming, a large number of collection classes and related interfaces are used;
A) Iterable: iterator interface;
B) Collection: Class Set interface;
C) List: List interface;
D) Set: DataSet interface;
E) Queue: Queue;
F) Map: Key-value pair combination ing table;
Iterable Interface:
① This interface allows the object to become the target of the "foreach" statement, that is, the set object can be iterated;
② Collection is a sub-interface of Iterable, so all class set objects can be accessed iteratively, but Map-based objects cannot;
③ Method:
Iterator <T> iterator ()
Function: returns an iterator that iterates on a group of T-type elements;
The Iterator is the class object that implements the Iterator/ListIterator interface. You can traverse the class set and access each element in the operation;
ListIterator extends the parent interface Iterator, which allows two-way traversal of sets and allows you to modify and delete elements;
Collection Interface:
Method defined by the Collection interface of the class set:
① Int size ()
② Boolean isEmpty ()
③ Booean contains (Object o)
④ Iterator <E> iterator ()
⑤ Object [] toArray ()
⑥ Boolean add (E e)
7. boolean remove (Object o)
⑧ Void clear ()
List, Set, Map
① The List interface extends the Collection feature: ordered and repeatable;
② The Set interface extends the Collection feature: unordered and repeatable;
③ Map is an object that stores keyword/value pairs. Given a keyword, You can query it to obtain its value. Both the keyword and value can be objects. Collection ing is not a sub-interface of Collection. Therefore, it cannot be traversed by the iterator itself;