samedi 28 mars 2015

Initialize arraylist with a higher capacity [duplicate]




This question already has an answer here:




When I read java blog about Collection, I find something about the ArrayList like this:



The default initial capacity of an ArrayList is pretty small. It is a good habit to construct the ArrayList with a higher initial capacity. This can avoid the resizing cost.



What does initialize arrayList with a higher initial capacity mean and how?


I only use this way:



ArrayList<String> places = new ArrayList<String>();
places.add("Buenos Aires");
places.add("Córdoba");
places.add("La Plata");


Does it mean that there is a way to pre-define the size of an arraylist like initialize the size of an array?




Aucun commentaire:

Enregistrer un commentaire