List, MAP, set three interfaces, when accessing elements, what are the characteristics of each? ----Turn

Source: Internet
Author: User

This problem belongs to the random play: Such a question comparison Test level, two aspects of the level: one is to really understand these content, the second is to have a strong summary and presentation capacity. If you understand, but the expression is not clear, in others is equivalent to do not understand.

First,Listwith theSethave similarities, they are all a collection of single-column elements, so they have a common parent interface, calledCollection. SetIt is not allowed to have duplicate elements, so-called repetition, that is, there cannot be two equal (note, not just the same) object, that is, supposeSetThe collection has aAobject, and now I'm going toSetcollection and then depositing aBobject, butBObjects andAObjectequalsequal, thenBobject is not stored in, so,SetCollection ofAddmethod has aBooleanwhen there is no element in the collection, thisAddmethod can be successfully added to the element, it returns thetruewhen the collection contains an elementequalswhen an element is equal, thisAddmethod cannot join the element and returns the result asfalse. Setwhen taking elements, it is impossible to say the first few, onlyIteratorthe interface obtains all the elements and then iterates through each element.

Listrepresents a set of priorities,Note that it's not sort by age, by size, by price, and so on. When we call it multiple timesAdd (Obj e)method, each time an object is added like a train station, tickets are queued in the same order, sorted by first served. Sometimes, you can also queue up, that is, callAdd (int index,obj e)method, you can specify where the current object will be stored in the collection. An object can be stored repeatedly in aList, each callAddmethod, the object is inserted into the collection once, in fact, not the object itself is stored in the collection, but in the collection with an index variable point to the object, when the object isAddSeveral times, that is, there are multiple indexes in the collection pointing to this object,xis shown. ListIn addition to being able toIteratorinterface to get all the elements, and then iterate through each element, you can also callGet (Index i)to specify the first few.

Mapwith theListand theSetdifferent, it is a collection of double columns, which haveputmethod, defined as follows:put (obj key,obj value), each time you store, you store a pair ofKey/value, you cannot store duplicateKey, this repeating rule is also based on theequalsCompare equal. The pick can be based onKeyget the appropriatevalue, i.e.get (Object key)The return value isKeyThe correspondingvalue. Alternatively, you can also use thekeySet()get all theKeythe combination Set<K>, you can also passvalues()get all thevaluethe combinationCollection<V>, you can also passentrySet()GetKeyand thevaluecombined into theMap.entryCollection of Objects Set<Map.entry<K,V>>.

List holds elements in a particular order, and can have repeating elements. Set cannot have duplicate elements , internal ordering. Map holds the key-value value, and value can be multivalued.


List, MAP, set three interfaces, when accessing elements, what are the characteristics of each? ----Turn

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.