Black Horse Program Ape--java Foundation--Set

Source: Internet
Author: User

----------Android Training, Java training, Java Learning Technology blog, looking forward to communicating with you. ------------ first, about the collection class in Javafirst look at the approximate framework flowchart      through these we can see, often we use the vector, ArrayList, HashSet. Treeset,hashmap. Hashtable,treemap, LinkedList classWith respect to vectors and arraylist, vectors are thread-safe and vectors are traversed. 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 version number can be used, and ArrayList can not

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 approach is synchronous. And the HashMap method is not. That means. Although you can use a hashtable in a multithreaded application without taking any special action, you have to provide an external synchronization for a hashmap in the same way. 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. This object's approach allows you to synchronize access to potential hashmap. The result of this is that when you don't need to sync, you can't cut off synchronization in Hashtable (for example, in a single-threaded application), and sync adds a lot of processing overhead.
  
The 3rd difference is that only hashmap can let you use NULL as a key or value for a table entry. Only one record in HashMap can be an empty key, but a random number of entries can be null 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.

Suppose it is necessary to use the Containkey () method to make a difference between the two cases.


  
Some information is suggested. When synchronization is required, use Hashtable and vice versa with HashMap. However, due to the need, HashMap can be synchronized, HashMap function than hashtable many other functions, and it is not based on a stale class, so some people feel that in all cases, HashMap priority over Hashtable.
Second, for the Java Collection framework


The comparison between them:

is ordered Do you agree that the element repeats
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)

  



,

Black Horse Program Ape--java Foundation--Set

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.