Performance, advantages and disadvantages of common collection classes

Source: Internet
Author: User
Go to: performance, advantages and disadvantages of common collection classes

We willArray, Dictionary <>, hashtable, list <>, arraylistAnd their respective advantages and disadvantages?

One-dimensional arrayIt is a linear table with the highest efficiency compared to other collection classes, but it is also relatively inconvenient to use;

Dictionary <> genericIt is a two-dimensional dictionary table based on the hash algorithm. Because the hash algorithm is used, the query time complexity is basically O (1), which is faster than that of hashtable, because the use of generics can avoid unpacking, packing operation;

HashtableIt is also a two-dimensional table based on the hash algorithm. Because its key and value are of the object type, its access to data needs to be boxed and deboxed, vs2003, which does not introduce the generic concept, is widely used. It is recommended to replace hashtable with dictionary;

Dictionary <> genericAndHashtableIt is a two-dimensional array table with an indefinite length, which means it is very easy to use without knowing the array length, and has many methods, such as containskey, add, remove, etc, the index of the retrieved array is no longer limited to the numeric index of the array. You only need to use the corresponding key type to index the index, which is very convenient to use.

AsList <> genericRecommended replacement in vs2005ArraylistThe reason is that arraylist needs to unpack and pack each element.
If list <> and arraylist are not sorted, sequential search is used by default. It is not as fast as hash search, but it has many built-in methods, suchSortAnd hashtable cannot be implemented, so the resources consumed for creation are also the most.

This article simply summarizes the features of the above several common collection classes and hopes to help everyone!

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.