The collection framework for Java

Source: Internet
Author: User

Originally I was going to have a chat on the experience on a straight talk about the collection, the result has written a lot of basic can not stop, so decided to open a new article

Since the collection is to be studied, the resources on the network are generally analyzed from 4 dimensions.

1. Whether to allow null

2. Whether duplicate data is allowed

3. Whether ordered: the order of storage and the order of reading is consistent

4. Whether the thread is secure.

First, let's take a look at ArrayList.

Whether to allow empty Can be empty
Whether to allow duplicates Can repeat
is ordered Ordered
is thread safe Thread not secure

First put a piece of code to see, verify

New Arraylist<string>(); List.add ("a"); List.add (null); List.add ("a"); List.add ("B"); System.out.println (List.tostring ());
[A, NULL, a, b]

The Add method is fast and has no synchronized adornments, so threads are unsafe

 Public Boolean Add (e e) {        + 1);  // increments modcount!!        elementdata[size++] = e;         return true ;}

 

The collection framework for Java

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.