The collection framework in Java

Source: Internet
Author: User

Defined:

collection classes in Java: A tool class, like a container, that stores any number of objects with common attributes.

Role:

Collections can:

1, in the interior of the class, the data are organized;

2, simple and fast search large number of entries;

3, some set interface, provides a series of orderly elements, and can quickly insert or delete elements in the middle of the sequence;

4, some set interface, provides a mapping relationship, you can quickly find the corresponding unique object by keyword (key), and this keyword can be any type.

vs. Arrays:

1, the length of the array is fixed, the set length is variable;

2, the array can only be accessed by the subscript element, the subscript type can only be a numeric type, and some of the collection can be any type to find the specific object being mapped.

Architecture of the Java Collection framework:

Collection interface

1, is the list, set and queue interface of the parent interface;

2, defines the method which can be used to manipulate list, set and queue--adding and deleting;

List interface and its implementation class--arraylist

    • List (sequence), elements are ordered, and repeatable;
    • The list can precisely control where the element is inserted, or delete the element at the specified position;
    • arraylist--array sequence is an important implementation class of list;
    • ArrayList the bottom layer is implemented by an array

In a generic collection, you cannot add an object other than the type specified by the generic and its subtypes, or you will get an error.

A qualified type in a generic collection, which cannot use a base type, must be wrapped with a basic type.

Set interface and its implementation class--hashset

    • Set (set), elements unordered, and can not be repeated;
    • hashset--Hash set, is an important implementation class of set;

Map interface

    • Map provides a mapping relationship where elements are stored as key-value pairs (key-value), and can be quickly searched for value based on key;
    • The key values in map exist as object instances of type entry;
    • The key value cannot be duplicated, and the value of value can be repeated;
    • Key to value is the relationship of multiple (one) to one;
    • The map interface provides a way to return a collection of key values, a collection of value values, and a collection of entry values;
    • MAP supports generics, forms such as:map<k,v>

HashMap class

    • HashMap is an important implementation class of map, and also the most common one, based on hash table implementation;
    • The entry objects in the HashMap are unordered arranged;
    • Both the key and value values can be null, but a hashmap can have only one mapping with a key value of NULL (the key value cannot be duplicated);

The collection framework in Java

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.