Overview of the Java collection

Source: Internet
Author: User

1 Java Collections Overview:2 3 Collection:4|---The list is ordered: The elements in the collection can be manipulated precisely by means of an index. Elements can be duplicated. 5 List provides the action to change and delete. 6 Add Add ( Element) Add (index,element);7 Delete Remove (Element) remove (index);8 Modify Set (index,element);9 query get (index);Ten|---Vector: is an array structure that can grow. is synchronous. Increase and check speed are slow, inefficient. Not currently in use.  One|---ArrayList: is the array structure, the length is variable, (the principle is: Create a new array +copying an array, the query is fast) is out of sync.  A|---LinkedList: Is the chain list structure, is not synchronized, adding and deleting the speed quickly. The query is slow. - can be used to implement stacks and queues. - stack: Advanced after first in last out FILO pistol magazine the queue: FIFO First out FIFO queue ticket - a list can store duplicate elements if the requirements require that the elements in the container must be unique. Look at the set set below. -                  -|---set: A collection that does not contain duplicate collection elements. And the method is consistent with collection. The set set takes out only one of the elements: an iterator. +|--HashSet: Hash table structure, unsynchronized, the way to guarantee the uniqueness of the element depends on: Hashcode (), Equals () method, the query is fast, only for the proof of uniqueness of the element.  -|--TreeSet: You can sort the elements in the set set, using a two-fork tree structure, how to guarantee the uniqueness of the elements?  + The result of using the object comparison method is 0, which is 0, as the same element, not saved.  A There are two ways to sort elements: at1, the elements themselves have a natural ordering, in fact, the implementation of the comparable interface rewrite the CompareTo method - if the element itself does not have a natural sort, or if the natural sort is not required, then only the second way -2, comparators: In fact, when you create a TreeSet collection, you specify a specific comparison in the constructor.  - you need to define a class to implement the comparator interface, overriding the Compare method - at this end, when you store objects in the collection, usually the object needs to overwrite the Hashcode,equals method - at the same time implement comparable interface, establish the natural ordering of objects. There is usually another method that will also replicate ToString (); in                    - tips for seeing collections: to Set sub-system: List set + the suffix of the subclass object is the system, and the prefix is the data structure name. - list: The new subclasses are all end-of-list and are usually non-synchronous.  the|--ArrayList: When you see the array, you know the arrays, the query is fast *|--LinkedList: See link, you know the list, adding and deleting fast $                   Panax Notoginseng Set: -|--HashSet: See hash, know hash table, query faster, and think of element unique, through hashcode (), Equals method guarantees element uniqueness the|--treeset: See tree, Know binary tree, can sort, sort think comparable-compareto comparator-Compare Method +      A         

Overview of the Java collection

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.