Java Collection Framework

Source: Internet
Author: User

Java Collection Framework Collection framework diagram

The collection interface provides a set of methods for manipulating mass objects, which provides basic operations such as adding, deleting.List

The most important feature of list is Order; it ensures that the elements are preserved in a certain order.

    • ArrayList: A list implemented with an array. Allows for fast random access, but it is slower to insert and delete elements in the middle of the list.
    • LinkedList: Sequential access is optimized. Inserting and deleting elements in the middle of a list is not expensive. The speed of random access is relatively slow. Commonly used as a stack, queue implementation.
Set

Object elements in set cannot be duplicated.

    • HashSet: Set that is designed to optimize query speed, sets the hash function to implement the index. To put into the hashset inside the object also has to define HASHCODE ().
    • The Linkedhashset collection also determines where the element is stored, based on the hashcode value of the element, but it maintains the order of the elements using the linked list.
    • TreeSet is the only implementation class for the SortedSet interface, which uses red-black trees to sort the treeset to ensure that the collection elements are in the sorted state.
Map

Key-value pairs.

    • HASHMAP: Based on the implementation of the hash table, an array of hash values is established for the key.

The difference between the Hashtable and the

1. Inherit different

public class Hashtable extends Dictionary implements Map
public class HashMap extends Abstractmap implements Map

The methods in 2.Hashtable are synchronous, and the methods in HashMap are not synchronized by default. In a multithreaded concurrency environment, you can use Hashtable directly.

3. Using different hash values, Hashtable directly uses the object's hashcode. The hash value is recalculated by the HashMap.

    • Linkedhashmap: Much like HashMap, but when traversing with iterator, it is accessed in the order of insertion or in the order in which it was first used (least-recently-used (LRU).
    • TREEMAP: Based on the implementation of red-black tree data structure.

Java Collection Framework

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.