Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  ArrayList vs. LinkedList  (Read 1132 times)
0 Members and 1 Guest are viewing this topic.
Offline weston

Junior Member





« Posted 2004-12-17 04:01:15 »

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.

for(int i = 1; i > 0; i++)
{
System.out.println(i+" cups of java downed");
}
Offline princec

JGO Kernel


Medals: 367
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2004-12-17 08:22:07 »

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 Smiley

Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #2 - Posted 2004-12-17 10:05:40 »

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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #3 - Posted 2004-12-17 10:24:35 »

Quote
Access is generally faster for gets in an ArrayList because it is backed by an array.


The difference in the described case should be insignificant unless, as Cas said, you are doing random access.

malloc will be first against the wall when the revolution comes...
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (18 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (70 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32

BurntPizza (37 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!