Dark Horse Programmer--java Foundation--Collection

Source: Internet
Author: User

----------Android Training, Java training, Java Learning Technology blog, look forward to communicating with you! ------------ first, about the collection class in Javafirst look at the approximate framework flowchart      as we can see from these, we often use vectors, ArrayList, Hashset,treeset,hashmap,hashtable,treemap, LinkedList classesWith respect to vectors and arraylist, vectors are thread-safe, and vectors are traversed to perform higher performance.

ArrayList and vectors function similarly,

Vectors exist since Java 1.0, ArrayList from Java 1.2 and newer.

So vector in Javame, card and other minor versions can be used, and ArrayList can't

ArrayList does not have the security of thread synchronization, but is faster.

Vector is thread safe.


and for HashMap and Hashtable,

There are three important differences between the Hashtable and the HashMap class. The first difference is mainly historical reasons. Hashtable is based on the old dictionary class, HashMap is an implementation of the map interface introduced by Java 1.2.
  
Perhaps the most important difference is that the Hashtable method is synchronous, and the HashMap method is not. This means that while you can use a hashtable in a multithreaded application without taking any special action, you have to provide an external synchronization for a hashmap as well. A convenient way is to use the static Synchronizedmap () method of the collections class, which creates a thread-safe map object and returns it as a encapsulated object. The method of this object allows you to synchronize access to potential hashmap. The result is that when you don't need to sync, you can't cut off synchronization in Hashtable (like in a single-threaded application), and synchronization adds a lot of processing overhead.
  
The 3rd difference is that only hashmap can let you use NULL as a key or value for the entry of a table. Only one record in HashMap can be an empty key, but any number of entries can be empty value. This means that if a search key is not found in the table, or if a search key is found, but it is an empty value, then get () returns NULL. If necessary, use the Containkey () method to differentiate between the two cases.
  
Some data suggest, when need to synchronize, use Hashtable, converse with HashMap. However, because HashMap can be synchronized when needed, HashMap functions more than Hashtable, and it is not based on a stale class, it is argued that hashmap in all cases takes precedence over Hashtable.
Second, for the Java Collection framework


The comparison between them:

is ordered Whether elements are allowed to repeat
Collection Whether Is
List Is Is
Set Abstractset Whether Whether
HashSet
TreeSet Yes (with binary sort tree)
Map Abstractmap Whether Use Key-value to map and store data, key must be unique, value can be repeated
HashMap
TreeMap Yes (with binary sort tree)

  



,

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Dark Horse Programmer--java Foundation--Collection

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.