Java Collection Differences

Source: Internet
Author: User

Interface

Briefly

Realize

Operating characteristics

Member Requirements

Set

Members cannot be duplicated

HashSet

Traverse members outside of an unordered manner

Members can be objects of any object subclass, but if the Equals method is overridden, notice that the Hashcode method is modified.

TreeSet

An externally-ordered traversal of a member, an additional implementation of a sortedset, a support for a subset, and other order-requiring operations

Members are required to implement the Caparable interface, or use comparator to construct TreeSet. Members are generally of the same type.

Linkedhashset

External traversal of members by member insertion Order

Members are similar to HashSet members

List

Provides index-based random access to members

ArrayList

Provides fast, index-based member access with better support for tail-member additions and deletions

Members can be objects of any object subclass

LinkedList

Better support for adding and removing members from any location in the list, but poor performance for index-based member access

Members can be objects of any object subclass

Map

Save key-value pairs of members, sort keys based on key-find operations, CompareTo or Compare methods

HashMap

To meet the user's common needs for map

Key members can be objects of any object subclass, but if the Equals method is overridden, notice that the Hashcode method is modified.

TreeMap

Supports an orderly traversal of keys, using HashMap to add and remove members, and finally generate treemap from HashMap; Additional implementation of SORTEDMAP interface, supporting the order of sub-map operations

Key members require implementation of the Caparable interface, or use comparator to construct treemap. Key members are generally of the same type.

Linkedhashmap

Preserves the insertion order of keys and checks the equality of keys and values with the Equals method

Members can be objects of any object subclass, but if the Equals method is overridden, notice that the Hashcode method is modified.

Identityhashmap

Use = = To check the equality of keys and values.

Members are using strictly equal

Weakhashmap

Its behavior relies on garbage collection threads, and there is no absolute reason to use less

Java Collection Differences

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.