Go Java Collection

Source: Internet
Author: User

1. Thread Safety
Thread safety means that multithreaded access to the same code does not produce indeterminate results.

2. List class and set class
The list class and set class are sub-interfaces of the collection collection interface.
Set sub-interface: unordered, no repetition allowed.
List sub-interface: Ordered, can have repeating elements.

Set and list comparison:
Set: The retrieval element is inefficient, the deletion and insertion efficiency is high, and insertions and deletions do not cause the element position to change.
List: And arrays, lists can grow dynamically, find elements efficiently, and insert deleted elements inefficiently because they cause other elements to change position.

Set and list specific subclasses:
Set
| ———— HashSet: Storing elements in a hash table, inserting deletes quickly.

List
| ———— ArrayList: Dynamic array
| ———— linkedlist: Linked list, queue, stack.

Array and Java.util.Vector
Vector is an old dynamic array that is thread-synchronized and inefficient, and is generally not in favor of use.

3, HashMap and Hashtable
A.hashmap removed the Hashtable contains method, but added the Containsvalue () and ContainsKey () methods.
B.hashtable synchronous, and HashMap is not synchronous, the efficiency is higher than Hashtable.
C.HASHMAP allows null key values, while Hashtable is not allowed.

4. Thread-Safe collection classes and non-thread-safe collection classes
LinkedList, ArrayList, hashset are non-thread-safe, vector is thread-safe;
HashMap is non-thread-safe, Hashtable is thread-safe;
StringBuilder is non-thread-safe and StringBuffer is thread-safe.

5. Set the applicable scene
Set or map is a better choice for applications that find and delete more frequently and with a large number of elements;
The ArrayList is suitable for scenes where elements are read by the location;
The LinkedList is suitable for scenarios where you want to work or insert a specified position;
Vectors are suitable for scenarios where a thread-safe ArrayList is needed;
Stack is suitable for thread-safe LIFO scenarios;
HashSet is suitable for storing non-repeating elements that are not required for sorting;
TreeSet applies to the storage of non-repeating elements to be sorted;
HashMap is suitable for most key-value access scenes;
The TREEMAP is suitable for key-value scenes that need to be sorted.

Transferred from: http://www.cnblogs.com/PMlog/p/5898320.html

Go Java Collection

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.