Arrays or ArrayLists - which is faster?
in
Programming Questions
•
1 year ago
Hi all,
I am working on a big game project, with lots of different objects. Right now I am using static arrays for them.
For example I have 100 arrays of the object "house". I probably don't need all 100, but I have to estimate it a bit, so there is some first unelegance. Then some houses disappear during the game, so their array is no longer needed. I set it to "null" in this case. And now everytime I cycle through the houses I have code like this:
I am working on a big game project, with lots of different objects. Right now I am using static arrays for them.
For example I have 100 arrays of the object "house". I probably don't need all 100, but I have to estimate it a bit, so there is some first unelegance. Then some houses disappear during the game, so their array is no longer needed. I set it to "null" in this case. And now everytime I cycle through the houses I have code like this:
- HouseObject[] house = new HouseObject[100];
- ...
- for( int i = 0; i < house.length; i++)
- if( house[i] != null)
- house[i].draw();
This works, but is somewhat unelegant. Now I am thinking about replacing all my static arrays with ArrayLists. I have just recently discovered ArrayLists, that is why I started off with static arrays.
The question I have is, is there a difference in performance between ArrayLists and static Arrays? Because performance is really an issue for my project, I would rather go with unelegant Arrays if they are faster. But when there is no difference I would replace them with ArrayLists. Because my code is allready huge, 10000 lines easily, I can not simply try it out.
So I hope someone here has some experience with this and can give me an advise.
Thank you!
The question I have is, is there a difference in performance between ArrayLists and static Arrays? Because performance is really an issue for my project, I would rather go with unelegant Arrays if they are faster. But when there is no difference I would replace them with ArrayLists. Because my code is allready huge, 10000 lines easily, I can not simply try it out.
So I hope someone here has some experience with this and can give me an advise.
Thank you!
1