Introduction to container classes in Java

Source: Internet
Author: User

I read the holding your objects chapter in thinking in Java and have a deeper understanding of Java containers. To sum up.

1. Container interfaces are classified into two categories: Collection and map. Collection is mainly used to store the same object, while map is mainly used to process the ing between one object and another.

2. Collection is divided into three types: List, set, and queue.

(1) List: used for linear storage of the same object, which is often used for sequential storage;

(2) Set: it is used for ordinary storage. It does not focus on the storage order and does not allow repeated objects;

(3) queue: The function is named as follows. It must be repeated first-in-first-out. This parameter is not explained ~~~

1. List has two sub-classes: arraylist and rule list.

(1) The long term of arraylist is search. After all, it is stored in arrays. The search performance is good, but it is not good at inserting data in the middle. This is easy to understand: when inserting data in the middle, all the following items must be moved to the back.

(2) The Long Term of the explain list is insert. If you have learned the data structure, you will know that the search performance is inferior to that of arraylist.

2. Set is divided into hashset and treeset.

(1) hashset is a type with high search performance. If you do not care about the sequence of element insertion, use hashset, because it can help you find or insert the elements you want in the shortest time. Note: The set type cannot store duplicate elements. Hashset has a subclass: linkedhashset. Its elements are arranged in the insert order.

(2) treeset is a tree structure. It is very simple to arrange all elements in ascending order. If you do not understand it, you can see the data structure ~

3. queue, which is not explained. first-in-first-out, has a subclass: priorityqueue. This is also relatively simple, that is, queues are sorted by priority. For example, if a passenger needs to wait in queue for boarding, you must let the passengers whose flight is about to take off first ~

3. the iterator is designed for collection services. Its functions are similar to the Java foreach syntax, but the difference is that if you want to operate on elements, iterator is more convenient, however, if you only need to traverse the collection and check the elements without processing them, use the foreach syntax.

Well, these are a brief introduction to the containers in Java. For more details, refer to thinking 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.