ArraysList can be dynamically allocated arrays
ArrayList<...> list = new ArrayList();
The <> is generic. Generics: All elements in the collection are uniform type. Generics can only be a reference type, not a basic type. The reason is that the collection is stored in address value, does not address basic types of value
ArrayList<int> list = new ArrayList();//错误 ArrayList<String> list = new ArrayList();//正确 ArrayList<Employee> list = new ArrayList();//正确
If you want to set ArrayList which stores basic types of data, you must use substantially corresponds to the type "packaging"
ArrayList<Integer> list = new ArrayList();//正确
ArrayList common methods:
- add: add an element to the array
- ensureCapacity: array.ensureCapacity (100) to assign a 100 internal array containing object and then calls 100 add. May ArrayList <Integer> array = new ArrayList <> (100), both are the same effect.
- size: Returns the number of array elements included in the list of actual
- trimToSize: when it is determined the size of the array is no change in the list, the method of adjusting the size of the storage area of the storage space the number of the current number of elements required. The garbage collector will reclaim the extra storage space
- get and set: to access and change the operation of the array elements. set can only be set existing elements
Both the flexibility to expand the array of skills and can easily access the array elements:
First of all,