Container classes in Java (list,set,map,queue)

Source: Internet
Author: User

Container classes in Java (list,set,map,queue)

First, the basic concept

The purpose of the Java Container Class library is to "save the object" and divide it into two different concepts:

1) Collection. A sequence of independent elements that obey one or more rules. The list must save the element in the order in which it was inserted, and set cannot have duplicate elements. The queue determines the order in which objects are produced, usually in the same order in which they are inserted, according to the queuing rules.

2) Map. A pair of "key-value pairs" objects that allow you to use keys to look up values. ArrayList allows you to use numbers to find values, so in a sense it associates numbers with objects. The mapping table allows us to use another object to find an object, also known as an associative array, because it associates some objects with other objects, or "dictionaries," because you can use a key object to look up a value object, as defined by using a word in a dictionary.

Complete container classification, including abstract classes and legacy constructs (excluding queue implementations):

Attention:

Collections is a class under Java.util that contains various static methods for collection operations, while collection is the interface under Java.util, which is the parent interface for various collection structures.

Ii. description of the container class

Iii. Summary

1. Various collection and various maps can automatically resize when you add more elements to it. The container cannot hold the base type, but the automatic wrapper mechanism carefully performs a bidirectional conversion between the base type and the wrapper type held in the container.

2. ArrayList: A large number of random accesses; LinkedList: frequently inserting or deleting elements from the middle of a table;

3. Various queue and stack behavior, there are linkedlist to provide support;

4. Map is a design that associates an object, not a number, with an object.

HashMap: Quick access; TREEMAP: Keep "key" always in sort state, no HashMap fast; Linkedhashmap: preserves the insertion order of elements, but also provides quick access through hashing.

5. Set does not accept duplicate elements.

HashSet: Provides the fastest query speed; TreeSet: keeps elements sorted; Linkedhashset: Saves elements in the order in which they are inserted.

6. The only overlap between map and collection is that map can use the EntrySet () and the values () method to generate collection.

Container classes in Java (list,set,map,queue)

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.