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]