A big wave of Java Attack (v)--java Collection overview

Source: Internet
Author: User

put " Java A Collection "is a container that can put multiple objects (actual: a reference to an object) and throw it in a container .

    1. jdk1.5 before being thrown into objects in the collection, Data type is lost. The default is object type
    2. 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?

  1. array:
    1. when initialized, determines the number of data in the hold is fixed
    2. data that has a mapping relationship cannot be saved
    3. for Bloom: values of the base type , or object (reference to object)
  2. Collection
    1. Just to compensate for the array I , II the deficiencies
    2. 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).

    1. Collection Tree
      1. Set unordered, non-repeatable
      2. List is ordered, repeatable
    2. Map tree, associative array


Third, the Java all the collections are divided into 3 class:

  1. 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
  2. List , similar to an array, you can remember the order in which elements are added, the difference is List the length is variable.
  3. 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

  1. Mapdiagram, split into
    1. Key jars (unordered, non-repeatable, similar Set collection) and the
    2. 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?

  1. Set , depending on the element itself
  2. List , depending on the index of the element
  3. 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

    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.