The overall framework of the Java Collections series

Source: Internet
Author: User

Collection-The Good times of childhood

set, suddenly let small series think of that period of good student time, set the first time I met her, the small part of the year is still a ignorant girl, also never thought will meet again in the world of computer, and then look back, set in mathematics is a basic concept, set is "a pile of Things", The "thing" in a collection is called an element, which consists of one or more elements called sets, and encounters, a world of computers, where a set is a set of variable numbers of data items that can also be a combination of 0 , which may share certain characteristics, You need to operate in some way, in general, the types of these data items are the same, or the base class is the same (if you use a language that supports inheritance), the list or array is generally not considered a collection because it is fixed in size, but in fact she is often used in implementations as some form of collection.

There is no collection in the world because of this need

There was no collection in the world, but because of this demand, there was a collection. When programming, often need to hold multiple data in the collection, of course, we can use an array to save multiple objects, but the length of the array can not be changed, once the array is initialized when the length of the array is specified, then the length of the array is immutable, if you need to save the number of changes in the data, Arrays are a little powerless, and arrays cannot save data with mappings, such as English -90, math -88, which looks like two arrays, However, there is a certain association between the elements of the two arrays, in order to save the quantity of uncertain data, and to save the data with the mapping relationship, also known as associative array,java provides the collection class, the main job of the collection class is to save and dress up her data, Therefore, the collection class is also known as a container class.

The deceased--array

to understand the collection in depth, the first thing we need to do is to get to know our deceased --Arrays , arrays are fixed in size, and the same array can only hold data of the same type, base type or reference type, andJavacollections can store and manipulate a set of data that is not fixed, and allJAVAcollections are located inJava.utilPackage,JAVAcollections can only hold data of reference types and cannot hold basic data types. JavaThe Collection class is a tool class that can be used to store multiple objects of varying amounts, and can implement commonly used data structures such as stacks, queues, and so on, in addition toJavacollections can also be used to hold associative arrays that have a mapping relationship.Javathe set can be broadly divided intoSet,Listand theMapthree types of systems, fromJDK1.5later,Javaincreased theQueueA collection of systems that represents a queue collection implementation. Some people want to have arrays that can be automatically expanded, so there's aListand someone wants to have no duplicate array so there's aSetand someone wants to have an array of automatic sorting, so there's aTreeSet, so anything is not produced in a vacuum, she has the value of her own existence oh`(*∩_∩*) -.

     collection Collection system

  The java collection can be divided into four parts, list Span lang= "en-US" >set , map , Tool class ( iterator iterators, enumeration Span lang= "ZH-CN" > enum class, arrays Vcollections java Collection class is primarily derived from two interfaces, collection map Two of them are the root interface of the collection framework, these two interfaces contain sub-interfaces or implementation classes, we use class diagrams to help us understand their relationship, first of all we see collection

the class drawing above is Collection a collection of systems in which Set and the List interface is Collection interface derives two sub-interfaces, which represent unordered and ordered sets, respectively. Queue is a Java provides a queue implementation that is somewhat similar to List.

Map Collection System

Then we'll see. Map the inheritance tree of the system, all the Map the implementation class is used to hold data that has a mapping relationship.


the class drawing above is MapThe implementation classes of the interfaces have some differences in function and usage, but they all have a functional feature,Mapeach item of data saved isKey-valueyes, that's becauseKeyand thevaluetwo values, just like the English one described earlier-90, Mathematics-88, each result is2a number of values, subject name and performance, for a score table, the subjects usually do not repeat, but the results can be repeated, usually according to the subject name of the search results, and not based on the results to query the subject name,Mapalso similar to this,Mapin theKeyis not to be repeated,Keyused to identify each item of data in the collection, if you need to queryMapdata is always based on theMapof theKeyto get.

Set&&list&&map

according to the class diagram above, we can put Javais divided into three main categories, whereSetThe collection class is similar to a sugar jar, which adds an object to theSetwhen the collection is inside,SetThe collection cannot remember the order in which this element was added, soSetThe elements inside cannot be duplicated, otherwise the system cannot accurately identify this element;ListThe collection is very much like an array, and she can remember the order of each added element, which can be repeated, justListthe length of the variable;MapThe collection is also like a sugar jar, but each of her data is made up of two values. If you accessListthe elements in the collection can be accessed directly based on the index of the element, if access is requiredMapthe elements in the collection, which can be based on each element'sKeyvisit and ask thevalue; If you accessSetThe elements in the collection can only be accessed based on the element itself, which is alsoSetThe reason why the elements in the collection are not allowed to repeat. As we mentioned before,JavaA collection can be divided into four parts,List,Set,Map, Tool Class (Iteratoriterators,Enumerationenumeration classes,Arrays (Collections),Iteratorinterface is alsoJavamembers of the collection frame, but sheCollectionSeries,Mapthe collection of series is different,CollectionCollection Series andMapThe collection series was mainly used to dress up her objects, whileIteratoris used primarily for traversal-that is, iterative accessCollectionthe elements in the collection,IteratorAn object is also known as an iterator. Iteratoris the tool that iterates over the collection, we sayCollectionrelies onIterator, is becauseCollectionimplementation classes are implemented.iterator ()function that returns aIteratorobject. In addition, there are two tool classesArraysand theCollections, they are the two tool classes that manipulate data and collections.

Small series of words: The blog, the small part of the main simple introduction of the Java collection of the overall framework, from the collection of our student era, to the collection of computers, Lu Xun said the world has no road, Walk more people also have the road, today Small said, the world does not have a collection, with such needs, but also have a set, with the overall framework above, the next small series of each class will be analyzed, I hope to have the need for the small partners to help, but also please the small partners more advice, look forward to ' (*∩_∩*).


The overall framework of the Java Collections series

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.