I need a data structure with the following requirements:
- Needs to be able to get elements by index (like a List).
- I will always just add / remove elements from the end of the structure.
I am inclined to use an ArrayList
. In this situation, it seems to be O(1)
both to read elements (they always are?), remove elements (I only need to remove them at the end of the list) and to add(I only add to the end of the list).
There is only the problem that time to time the ArrayList will have a performance penalty when it's completly full and I need to add more elements to it.
Is there any other better idea? I don't think of a data structure that'd beat the ArrayList
here.
Thanks