The performance will very much depend on the VM involved, and a variety of other considerations.
The ArrayList is backed by an array, when storing data into the ArrayList, more work is performed, for example:
- A nullity check (to see whether the ArrayList reference is non-null).
- A bounds check — to handle the resizing logic, to resize the array that backs its. This array is resized in chunks.
so the size of the list is usually smaller than the length of the array. - Potentially a virtual method indirection, depending on whether the JIT has managed to inline the call.
- Its worth noting that usually the performance of one single method call doesn't matter much, usually its not worth sacrificing good design for few micro-seconds. Only optimize your fast paths, its likely most of your code will be run infrequently.
No comments:
Post a Comment