ArrayList ensureCapacity example

If you have an ArrayList that already has lots of elements and you are trying to add more elements to the ArrayList, this may degrade the performance of the system. To improve the performance, you may consider using the ensureCapacity() method.

public void ensureCapacity(int minCapacity) , ensures that the ArrayList can atleast hold the number of elements that are specified in int minCapacity.

So when you try to add more elements to the already loaded ArrayList, you can be sure that their is very minimum performance issue.

ArrayList ensureCapacity example

Output

Reference

1. ArrayList

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn