Constructor ArrayList java
Constructors for ArrayList ObjectsTo declare a reference variable for an ArrayList do this: ArrayList The future ArrayList object will contain an array of references to objects of type E or to a descendant class of E. To declare a reference variable and to construct an ArrayList, do this: ArrayList The array has an initial capacity of 10 cells, although the capacity will increase as needed as references are added to the list. Cells will contain references to objects of type E (or a descendant class). This may not be very efficient. If you have an idea of what the capacity you need, start the ArrayList with that capacity. To declare a variable and to construct a ArrayList with a specific initial capacity do this: ArrayList The initial capacity is the number of cells that the ArrayList starts with. It can expand beyond this capacity if you add more elements. Expanding the capacity of an ArrayList is slow. To avoid this, estimate how many elements are needed and construct an ArrayList of that many plus some extra. |