put " Java A Collection "is a container that can put multiple objects (actual: a reference to an object) and throw it in a container .
- jdk1.5 before being thrown into objects in the collection, Data type is lost. The default is object type
- jdk1.5 Data types are not lost because "Generic " (as the focus of the following) was introduced
This article will combine data structure, focus on Java of the 4 the functions and usages of the collection system, and how to choose different application scenarios?
One, the same is used to "store data", can use "array", there can use "collection", what is the difference?
- array:
- when initialized, determines the number of data in the hold is fixed
- data that has a mapping relationship cannot be saved
- for Bloom: values of the base type , or object (reference to object)
- Collection
- Just to compensate for the array I , II the deficiencies
- Only for Sheng: object (reference to object)
Second, Java The collection class is primarily derived from two interfaces: Collection and the Map , the two interfaces also contain sub-interfaces and implementation classes (simplified version).
- Collection Tree
- Set unordered, non-repeatable
- List is ordered, repeatable
- Map tree, associative array
Third, the Java all the collections are divided into 3 class:
- Set , similar to a jar, objects are randomly added to Span lang= "en-US" style= "FONT-FAMILY:CALIBRI; font-size:11pt ">set collection, set collections cannot remember the order in which elements are added. So set
- List , similar to an array, you can remember the order in which elements are added, the difference is List the length is variable.
- Map , which is similar to a jar, except that each data item in it is made up of two values.
Map Interface , dictionary / associative arrays, key-value pairs are stored, Key and the value One-way
- Mapdiagram, split into
- Key jars (unordered, non-repeatable, similar Set collection) and the
- value can (repeatable, can be found by index, similar List Collection "Difference: here is Key index instead of a numeric index ")
Iv. How to access the elements?
- Set , depending on the element itself
- List , depending on the index of the element
- Map , according to Key to access the corresponding value
Related articles:a big wave of Java Strikes (vi) collection and iterator interface of the--java collectiona big wave of Java Attack (vii) set interface of--java seta big wave of Java Attack (eight) list interface of--java collection
A big wave of Java Attack (v)--java Collection overview