The collection in Java--the main difference

Source: Internet
Author: User

The Collection collection interface, which refers to the Java.util.Collection interface, is the superclass interface of the set, List, and Queue interfaces.

List:

  Lists are the list of things that concern the index.

The list can have duplicate elements.

The list can have null values.

List is used to store the same type of data, only one store, cannot store key value pairs.

List is stored in order.

List is mainly used to vector,arraylist,linkedlist.

  Vector: is an array-based list that adds some functionality on top of the array and is thread-safe .

ArrayList: is an array-based list, non-thread-safe .

  linkedlist: A list that is not array-based is equivalent to a linked list in C + +, each of which contains two things: 1. Data of the node itself; 2. Information for the next node. So when adding to the LinkedList, deleting the action doesn't have to be a lot of data movement like array-based lists.

  so vector ArrayList is suitable for queries, linkedlist for adding deletes .

Set

  Set the implementation base is map.

Set stores the key-value pair format data.

Set does not allow duplicates.

  Set is mainly used to hashset,linkedhashset,treeset.

  HashSet: no order.

  linkedhashset: HashSet subclass, is a linked list, in order of insertion.

  TreeSet: Naturally ordered.

Queue:

The queue is used to save the list of tasks that will be performed.

  The LinkedList also implements the queue interface, which enables FIFO-first queues.

  priorityqueue is used to create a priority queue for natural sorting.

The collection in Java--the main difference

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.