Learn about the collection with Mr. Wang (a) Why use collections and Java Collections overview

Source: Internet
Author: User

Why to use collections and Java Collections Overview Speaker: Wang Shaohua QQ Group No.: 483773664
Learning Goals

1 Understanding why collections are used

2 Mastering the Java Collection framework

One, using array defects:

In an electronic pet system, if you want to store multiple pet information, you can use an array. For example, you can define an array of 50 dog types that stores information for multiple dog objects. However, there are some obvious flaws in the use of arrays:

    • The array length is fixed and does not fit well with the dynamic change in the number of elements. If you want to store more than 50 dogs, the array length is insufficient, and if you store only 20 of your dog's information, the memory space is wasted.

    • The array length can be obtained through the array name, but the number of dogs actually stored in the array cannot be obtained directly.

    • The array uses the storage method of allocating contiguous space inside, and the corresponding dog information can be obtained quickly according to subscript. But according to the dog's information search efficiency is low, need to compare many times.

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/7F/B5/wKioL1cp2d6RTbrwAAAOrb1hf8o284.png " data_ue_src= "E:\My knowledge\temp\2a940c19-49a8-498a-a0dc-91b50de5fab8.png" >

Compare

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/7F/B7/wKiom1cp2QnjS6Z2AAByFXqLSBE773.jpg " data_ue_src= "E:\My knowledge\temp\c727b571-deb8-4270-b2e0-993e8a353dae.jpg" >

Binary Method Search

Second, the array can not complete the requirements

In the storage of dog information, you want to store the dog's name and dog information, there are one by one corresponding relationship. As shown

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/7F/B5/wKioL1cp2d7i5YrlAAAVF6-dRBc974.png " data_ue_src= "E:\My knowledge\temp\cf938528-93be-4044-bb89-a318e17eb095.png" >

The array must not be able to complete this requirement

Iii. Overview of the Java collection (i) What is a Java collection
    • Java provides a collection class to hold data that is uncertain in quantity and to hold data that has a mapping relationship.

    • Collection classes are primarily responsible for saving and holding other data, so the collection class is also known as the Container class

    • All collection classes are located under the Java.util package

(ii) Java collection framework
    • The Java collection class is mainly derived from two interfaces: collection and map.

    • Collection interface, sub-interface and its implementation class inheritance tree

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/7F/B7/wKiom1cp2QrTlcYmAACUNnjxL2Y277.jpg " data_ue_src= "E:\My knowledge\temp\1f99cd44-575c-485b-9bc1-6d7674bf0058.jpg" >

The set and list interfaces are two sub-interfaces derived from the collection interface, which represent unordered sets and ordered sets, respectively;

The queue is an implementation of the queues provided by Java.

    • The inheritance tree of map system

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/7F/B7/wKiom1cp2QqA2InQAAB70D0nBgE964.jpg " data_ue_src= "E:\My knowledge\temp\16ddafae-9c01-4625-a9fd-b1b4b4db8ea8.jpg" >

Each data that the map saves is a Key-value pair, which consists of a key and value two values.

The key in the map is not repeatable, the key is used to identify each item of data in the collection, and if you need to consult the data in the map, always follow the map key to get

For example, to save a person's information (including the identity card number and name)

(iii) Summary

Java collections can be divided into three main categories

Set: Similar to a large jar, the characteristics of the elements: disordered, non-repeatable. The most common implementation class: HashSet

List: Like an array, just the variable length of the list, element features: ordered, repeatable. The most common implementation class ArrayList

Map: Like a jar, elemental features: There are two values to make up. The most common implementation class: HashMap











From for notes (Wiz)

Learn about the collection with Mr. Wang (a) Why use collections and Java Collections 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.