This article is a brief introduction to the collection, which will be written in a few articles to explain the various collections in detail.
Collection Concepts
We are learning object-oriented language, object-oriented language description of things is through the object, in order to facilitate the operation of multiple objects, we have to store the object. To store multiple objects, you cannot be a basic variable, it should be a variable of the container type, so the collection is born.
Collection system
1. Collection interface
Collection is the most basic set interface, which defines a set of objects that are allowed to be duplicated. The collection interface derives two sub-interface sets and lists, respectively defining two different storage methods, as follows:
2. Set interface
The set interface inherits from the collection interface, which does not provide an additional method, but the elements in the collection class that implement the set interface are unordered and non-repeatable.
Features: unordered and non-repeatable.
3. List interface
The list interface also inherits from the collection interface, but, contrary to the set interface, the elements in the collection class of the list interface are object-ordered and repeatable.
Features: Ordered and repeatable.
Two important implementation classes: ArrayList and LinkedList
1.ArrayList features are ordered and repeatable
2.LinkedList is a doubly linked list structure.
4. Map interface
Map is also an interface, but does not inherit the collection interface. This interface describes a key-to-value mapping that is never duplicated. The map interface is used to maintain key/value pairs (Key/value pairs).
Feature: It describes a mapping of key-to-value values that are never duplicated.
Two important implementation classes: HashMap and TreeMap
1.HashMap, the Chinese call hash list, based on the hash table implementation, the characteristic is the key value pair's mapping relation. A key corresponds to a value. The ordering of elements in HashMap is not fixed. More suitable for inserting, deleting, and positioning elements.
2.TreeMap, based on the red and Black Book implementation. The elements in the TreeMap maintain some sort of fixed order. More suitable for sequential traversal of elements.
5. Iterator interface
Iterator interface, there is an exception in C # IEnumerator, they are all collection accessors that iterate over the objects in the collection.
All container classes that implement the collection interface have a iterator method that returns an object that implements the iterator interface. The iterator object is called an iterator, and the iterator interface method iterates through each element of the collection iteratively, and can remove the appropriate element from the collection.
The concept of ———— set of Dark Horse programmers (I.)