ArrayList vs. LinkedList

I’m storing a group of objects that will have methods called on them (update(), render()) every frame inside an ArrayList. What I’m wondering is if it would be faster to use a LinkedList since I will never grab an item from the middle. Everytime I use the data structure I will be doing a complete sequential traversal.

I was originally doing this with a LinkedList, but I ran into problems with concurrent modification while using an iterator to traverse the list. The concurrent modification was because of awt events which were on a seperate thread. I figured I could avoid this by storing all the events in a queue and processing them at the correct time, but I’ve moved on to lwjgl since then and I don’t think it will be a problem.

I’m also thinking of writing my own data structure for doing this so that I can avoid casting from Object, but I’m not sure if I should implement it as a linked structure or an array based structure (only worried about speed really).

I realize this isn’t exactly a performance bottleneck but I’m just wondering about it because I’m writing some reusable code that should be as efficient as possible.

LinkedList is generally far more useful than ArrayList is when:
a) The size of the list is unknown and could be large
b) You never need to randomly access elements
c) You frequently iterate through it, and remove or insert elements.

Cas :slight_smile:

Access is generally faster for gets in an ArrayList because it is backed by an array. If your list does not change size during play, I would recommend ArrayList.

[quote]Access is generally faster for gets in an ArrayList because it is backed by an array.
[/quote]
The difference in the described case should be insignificant unless, as Cas said, you are doing random access.