A probe into the list,set of Java collection classes

Source: Internet
Author: User

Collection is a top-level interface, and in the collection class there is also a map of the top-level interface (refer to the Java Collection Class map inquiry), this article through a class diagram describes the list and set the basic structure.



Class Diagram parsing:

Collection is a top-level interface that defines a series of methods, and list and set are the interfaces that inherit from Collection.

Each collection can produce a iterator (refer to Java iterator and iterator mode), which can be traversed using iterator.

Abstractcollection is an abstract implementation of collection, and all implementation classes inherit from Abstractcollection.

Abstractlist inherits from Abstractcollection and implements the list interface, all of the list implementation classes inherit from Abstractlist.

Both ArrayList and LinkedList inherit from Abstractlist, and LinkedList implements the queue interface, so linkedlist can be used as a queue. Vector is a synchronized list, which has been deprecated because of the synchronized cost.

ArrayList and LinkedList comparison:

The ArrayList is implemented internally by the array, so access is faster, and the access speed is not affected as size increases, but when elements are added or removed, it is expensive to copy (reference) by moving the element or even creating a new array.

The LinkedList is implemented internally by the linked list, and when size increases, the access speed is significantly affected, but the cost of deleting the element is less.

Abstractset inherits from Abstractcollection and implements the set interface, all of the set implementation classes inherit from Abstractset.

Java set design and map similar, you can refer to the Java Collection Class map to explore

Hashset used as a universal set

Linkedhashset and map (reference to the Java Collection Class map) have a common aspect of saving data in the order in which they are inserted.

TreeSet implements the SortedSet interface and is an ordered set.

Vector,stack has not been recommended for use

In addition, collections is a tool class that contains a large number of operations on the collection class, and there is not much to describe here


A probe into the list,set of Java collection classes

Related Article

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.