Java Basic Data Structure summary

Source: Internet
Author: User

Import java.util.Hashtable;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import Java.util.HashSet;
Import Java.util.LinkedHashMap;
Import Java.util.LinkedHashSet;
Import java.util.LinkedList;
Import Java.util.Stack;
Import Java.util.TreeMap;
Import Java.util.TreeSet;
Import Java.util.Vector;

Today I saw some basic collections provided by the Java system, summarized here, is a summary of learning.

All of their collections are basically based on the collection interface and the Map interface.

Collection

1.list (ArrayList, LinkedList (for frequent insertion and deletion), Vector (thread safe), Stack (advanced back-out))

2.set (HashSet (unordered, find entry based on hash value), TreeSet (when sorting is required), Linkedhashset (when ordered && ordered iterations are used))

Map

1.TreeMap (used when sorting is required)

2.HashMap (unordered, find Entry,concurrenthashmap (thread safe) according to the hash value of key, Linkedhashmap (used in ordered && ordered iterations), HashTable (thread safe)

Then we make a simple analysis of each of the specific sets.

ArrayList: Array collection, no capacity limit, non-thread safe

LinkedList: Based on a two-way list mechanism, insert creates a entry object and toggles the front and back element references, non-thread safe

With respect to ArrayList, its advantage: Add,remove is faster because only the front and back elements need to be manipulated, and ArrayList needs to manipulate the entire list

Get,set slower to think ArrayList is orderly, linkedlist need the entire traversal

Vector: Similar to ArrayList, the biggest difference is thread safety, and the automatic expansion mechanism is twice times (ArrayList1.5 times)

Stack: Inherit from vector, press stack, LIFO (Push,pop. Peek

All HashSet are joined by hashcode a value from the object and then added to the set by this value

HashSet: Based on HASHMAP implementation, non-thread-safe, can save a null (hash table by using the form of hash table to store information, the elements in the collection are not in a particular order, and can change at any time)

TreeSet: (SortedSet) based on TREEMAP implementation, key needs to implement comparator, implement sorting

Relative to HashSet: support sorting

Linkedhashset: Based on the hash value to determine the location of the element storage, while using the linked list to maintain the order of the elements before, so he is orderly

Advantage: Iterative speed is better than hashset, insert delete check (because the relationship between the elements need to be maintained before and after maintenance)

HashMap: Finds the position of entry in another array based on the hash code in the array, traversing with iterator

HashTable: Thread safe, do not allow NULL, then use enumeration

TREEMAP: A map that can be sorted

Linkedhashmap: Relative to HashMap, the time of insertion is orderly, so when sorting

Java Basic Data Structure summary

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.