List as ordered and repeatable lists
The class that implements the list interface is primarily ArrayList
The following is the test code for ArrayList
Importjava.util.ArrayList; Public classDemo4 { Public Static voidmain (String [] args) {ArrayList A1=NewArrayList (); A1.add (NewInteger (11)); A1.add (NewInteger (23)); A1.add (NewInteger (65)); A1.add (NewInteger (28)); A1.add (NewInteger (72)); A1.add (NewInteger (98)); SYSTEM.OUT.PRINTLN (A1); //Conversion GroupObject a[] =A1.toarray (); intsum = 0; for(inti=0; i<a.length; i++) Sum+=((Integer) a[i]). Intvalue (); System.out.println ("Sum:" +sum); }}
Code Analysis:
Instantiate an ArrayList object first A1
Adding elements to the Add () method
Output the entire list
Then convert the collection A1 to the array, using the method of ToArray ()
The Intvalue () method is used in the calculation of the sum of the arrays: you can convert the wrapper type to the underlying type value
Finish
Java Review the list interface of the collection class