The collection Framework (collections framework)---consists primarily of a set of interfaces used to manipulate objects. Different interfaces describe a different set of data types. The collection framework in Java defines a set of specifications for representing, manipulating, and decoupling specific operations from implementation details. In fact, you can think of a set as a micro-database, operation is nothing more than "delete and change" four kinds of operations, we learn to use a specific set of classes, we need to make these four operations of the space-time complexity to clear, basically can be said to master this class.
First, the main concept of the collection framework:
The main idea in a nutshell is: To provide a set of "small and beautiful" API. The API needs to be programmer-friendly and add new functionality to enable programmers to get started quickly. To ensure that the core interface is small enough, the topmost interface (that is, the collection and map interfaces) does not differentiate whether the set is mutable (mutability) and can be changed (modifiability). Whether it is possible to change the size (resizability) of these subtle differences. Conversely, some operations are optional, and when implemented, throws unsupportedoperationexception to indicate that the collection does not support the operation. The implementation of the collection must declare in the document that those operations are not supported. To ensure that the top-most core interfaces are small enough, they can only contain the following scenarios: basic operations, such as the previous said "additions and deletions" there is a compelling performance reason what an important implementation Would want to override it. In addition, all collection classes must be able to provide friendly interaction, including array objects that do not inherit the collection class. Therefore, the framework provides a set of methods that allow the collection classes and arrays to be converted to each other, and map can be thought of as a set.
Two major base classes collection and map
In the class inheritance system of the collection framework, the topmost layer has two interfaces: collection represents a set of pure data, and map represents a set of key-value pairs.
Generally inherited from a collection class of collection or map, it provides two "standard" constructors: constructors without parameters, creating an empty collection class with a constructor of the same type as the base class (collection or map). Creates a new collection class with the same element as the given parameter because the interface cannot contain constructors, so the conventions of the above two constructors are not mandatory, but in the current collection framework, all subclasses inheriting from collection or map follow this convention.
Collection is the most basic set interface, and a collection represents a set of object, the collection element (Elements). Some collection allow the same elements while others do not. Some can sort and others can't. The Java SDK does not provide classes that inherit directly from collection, and the Java SDK provides classes that inherit from collection, such as list and set. All classes that implement the collection interface must provide two standard constructors: a parameterless constructor is used to create an empty collection, and a constructor with a collection parameter is used to create a new collection. This new collection has the same elements as the incoming collection. The latter constructor allows the user to copy a collection. How do I traverse every element in the collection? Regardless of the actual type of collection, it supports a iterator () method that returns an iteration that uses the iteration to access each element of the collection one at a time.
Map:map does not inherit the collection interface, and map provides a key-to-value mapping. A map cannot contain the same key, and each key can only map one value. The map interface provides views of 3 collections, and the contents of the map can be treated as a set of key sets, a set of value collections, or a set of key-value mappings.
HashMap and Hashtable are similar, except that HashMap is non-synchronous and allows NULL, which is null value and null key. , but when HashMap is treated as collection (the values () method can return collection), its iteration sub-operation time overhead is proportional to the capacity of HashMap. Therefore, if the performance of the iterative operation is quite important, do not set the initialization capacity of the hashmap too high or load factor too low.
Java Collection Framework