Java Collection Framework collection (3)

Source: Internet
Author: User

According to the idea of Java programming, the Java collection is also called a container, which is divided into two categories, collection and map, in terms of single and double slots, both of which are interfaces.

First, Collection

Collection below is divided into three sub-interfaces, namely Set,list and queue, respectively, their characteristics are:

1.Set: The element is unique, that is, the elements in the set can never be duplicated, as is the concept of a set in mathematics. All of its implementation classes have the same characteristics.

There are three main implementation classes: Hashset,linkedhashset,treeset

    • The underlying implementation of HashSet is the key in the HashMap, so it is characterized by disorder and non-repetition;
    • The Linkedhashset bottom implementation is linkedhashmap, characterized by the elements becoming orderly. Here the order refers to the same traversal sequence and the insertion order.
    • TreeSet the underlying implementation is TREEMAP, is also ordered, here the order refers to the size of the element itself, for the integer, String, itself has implemented the comparable interface, so they are comparable. Developer-defined objects require their own implementation of the comparable interface to facilitate program execution of element comparisons.

2.List: Ordered, the List is ordered and repeatable, and here the order is only the same as the traversal sequence and the insertion order. The most common implementation classes:

    • ArrayList bottom implementation is an array, so the query efficiency is high, and the efficiency is low;
    • LinkedList bottom implementation is linked list, longer than insert Delete, query efficiency is low.

3.Queue: Queue, characterized by FIFO, only allow deletion in front of queue, queue back-end insertion, commonly implemented class Priorityqueue.

Second, Map

If arrays and lists implement mapping of subscript and element objects, then map implements the mapping between objects and objects.

Main implementation classes: Hashmap,linkedhashmap and TreeMap

A hash table is used at the bottom of the HashMap to enable quick lookups.

The most important feature of Linkedhashmap is that the key value is ordered, and the traversal order is the same as the insertion order.

The bottom of the treemap is a red-black tree, and the newly inserted elements are compared to the elements in the map and inserted into the inserted position. The TreeMap object must implement the comparable interface.

Java Collection Framework collection (3)

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.