This is the explanation of the JDK API1.6.0 for ArrayList.
ArrayList
Creating classes with Java generics is complex, but applying predefined generics is simple. For example, to define the ArrayList used to hold an Apple object, you can declare Arraylist<apple>, which is a type parameter within the angle brackets (which can be multiple). It specifies the type that the container can hold.
By using generics, you can prevent objects of the wrong type from being placed in the container at compile time .
The ArrayList is transformed upward into a list.
It should be noted that the type conversion is not necessary when the element is removed from the list. Because list performs a transformation for you when it calls get (), he knows what type you are saving.
This way, by using generics, not only does the compiler check the type of objects you place in the container, but you can use a clearer syntax when using objects in the container. At the same time, you can use foreach to select each element of the list.
Referencing the code from the previous blog, if you create multiple classes that inherit the Apple () class , such as Class Fuji extends Apple () {}, then use the predefined generic arraylist<apple> Apples=new arraylist<apple> (); , use the Add () method to add an object instance of each Apple subclass, such as Apples.add (New Fuji ()); , and then output using the Foreach method, the result is similar to [email protected] .
Parsing: The output of the program is generated from the default ToString () method of object. The method prints the unsigned hexadecimal representation of the class name, followed by the hash code (the hash code is generated by the Hashcode () method).
Java holds object "2" ArrayList container continuation