My intuition says arrays are faster than arraylist because arraylists are implemented using arrays that resize as it fills up/loses elements.
I just wanted to confirm if this is true or not, implying there’s never a reason to use an arraylist if you know the number of elements you want to hold.
Any performance difference will be negligible, especially if you initialize your arraylist with an
initialCapacity. Write your code in whatever way makes it the most readable and maintainable, and try not to optimize stuff like this unless you’ve determined through testing that you are getting a significant performance hit from it.Potential reasons to use
ArrayList:contains, etc.)Iterable,Collection, andList, and can therefore be used in a lot of API calls that are interface-based.