two months ago when preparing for a soft test, a simple theoretical summary of the most commonly used data structures and algorithms, such as: linear tables , linked lists , graphs . In Java development, the JDK provides us with a series of corresponding classes to implement the primary data structure. The container API provided by the JDK is located in the Java.util package. This article is mainly through a simple introduction of the collection collection, to the reader simply explain the basic definition of each class and its role, for the following learning to do a foreshadowing.
First, let's take a look at the basic structure of the collection collection:
1. Collection Interface
Collection is the most basic set interface, which defines a set of objects that agree to repeat. The collection interface derives two sub-interface sets and lists, each of which defines two different storage methods, such as the following:
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 cannot be repeated.
Features: unordered and non-recurring.
3. List interface
The list interface is also inherited 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.
Characteristics: orderly and repeatable .
Two important implementation classes: ArrayList and LinkedList
1.ArrayList is characterized by an orderly 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. The interface describes a mapping of a key-to-value that is never repeated. The map interface is used to maintain key/value pairs (Key/value pairs).
Feature: It describes the mapping of a key-to-value that is never repeated.
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 corresponding 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 , there is an exception in C # IEnumerator, they are all sets of interviews, used to iterate through 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 theiterator interface method iterates through each element of the collection in an iterative manner and removes the appropriate element from the collection.
<span style= "font-size:10px;" >iterator it = Collection.iterator (); Get an Iteration sub while (It.hasnext ()) { Object obj = It.next ();//Get Next element } </span>
6. Comparable interface
Comparable can be used for comparison implementations, classes that implement the comparable interface are able to determine how the class objects are sorted by implementing the Comparato method.
Summary
The collection collection is derived from the collection and map interfaces, respectively, and collection has two frequently used sub-interfaces list and set, respectively, to represent ordered and repeated, unordered non-recurring collections. Map, however, stores the mappings for Key-value.
The summary above looks very much, very cumbersome, in fact you just have to remember that:collection is used to deal with various data structures, according to the characteristics of various data structures to understand , everything will become simple.
Although this blog is a bit rough, it also hopes to help you understand the collection a little bit (especially for the organization). The following blog post, I will update some of the basics about threading, please continue to follow.
"Java reading notes"--collection set of six interfaces (Collection, set, List, Map, iterator, and comparable)