Help choosing the right data structure
Posted
by devoured elysium
on Stack Overflow
See other posts from Stack Overflow
or by devoured elysium
Published on 2010-05-31T16:24:54Z
Indexed on
2010/05/31
16:32 UTC
Read the original article
Hit count: 183
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
© Stack Overflow or respective owner