[Java Self-study Nineth day]

Source: Internet
Author: User

Differences in collection classes

The difference between a list collection class and a Map collection class: whether there is a key value (the List collection class has no key value, and the Map collection class has a key value)

Key: A value that uniquely identifies a thing

A key value is a property that is added separately to uniquely identify a thing, so do not use the property of the transaction itself to do the key value

The difference between the ArrayList class and the vector class is the same as the HashSet class and the HashMap class.

The ArrayList class and the HashSet class are thread asynchronous, the thread asynchronous restriction cannot realize the network real-time request, must be oneself and oneself, the single-machine behavior can, has the high efficiency but the security is low.

Vector class and HashMap class are thread synchronization, can realize the requirements of real-time network, generally for the network, with low efficiency but high security features, pay attention to security can use these two classes.

It is generally selected from among these four classes.

Generics and reflection mechanisms

Because of the type conversion error, the Java Virtual machine will not error when writing, and in the run times abnormal, so security is very obvious, so we need generics to compensate for this problem, we propose generics, we can add element objects in the collection class, we do not have to strongly turn.

The reflection mechanism is that all methods and members of a generic fixed class can be displayed to provide a mechanism by which programmers can determine whether a program is written incorrectly.

①arraylist A1 = new ArrayList ();

Ls Ls1 = new ("Potato chips", 5f);

Yl Yl = new ("Cola", 10f);

A1.add (LS1);

ls LS2 = (ls) a1.get (0);

②yl yl1 = (Yl) a1.get (0);

When you modify the ① statement to arraylist<ls> a1 = new arraylist<ls>;

② statement will compile the error, because the existence of <Ls> Limited A1 this ArrayList collection class object can only hold the Ls class.

[Java Self-study Nineth day]

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.