The arraylist class implements the list interface, which is a sub-interface of the collection interface and mainly adds methods for retrieving Objects Based on indexes.
Arraylist uses arrays to implement the list interface.For quick object acquisition, good performance can be achieved. However, when you delete an object or insert an object
,Especially when an object is inserted or deleted at the front end of the arraylist, the objects behind the internal array must be moved in sequence at a relatively high cost. Relatively slow
(Using the consumer list is better in this regard ).
There is a big difference between arrays and array lists. Arrays are a feature of the Java language. For each element type T, there is an array type T []. However, the arraylist class is a definition.
Class Library in the Java. util package, which is a "common" type for storing object type Elements. Note: To extract elements from the array list, type conversion is required.
The add () method can add new elements to the array list:
List list = new arraylist ();
List. Add (new element (......));
List. Add (new element (......));
The arraylist class manages the internal array referenced by an object and may use up the array space. If add is called and the internal array is full, the array list will automatically create a larger array and automatically copy the objects in the small array to the large array.
The Set () method can be used to set the element values in the array list:
List. Set (I, new element (......));
The get () method can get the elements in the array list. The returned type is object.
Element E = (element) list. Get (I );
The size () method returns the length of the current arraylist.
List. Size ();