Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Linked Lists and vectors- any difference?

Started by Darragh Mar 18, 2005 at 7:36 AM 1 replies 900+ views
Original Post
Darragh
Darragh
First of all I'd like to say hello to all the GD.Net members as this is my first post here! I'm a student currently study a Computer Applications course which also involves learning some java. Anyhow i've decided to take the plunge and apply for a games design course which hopefully i'll be doing next year- with any luck! In the meantime i've begun experimenting by working on a Wolfenstein3D style 3D Engine using Java and JOGL. Its going quite well at the moment with the renderer up and running, basic bounding box collision dection, texturing, doors, and a simple 3DS model loader. Anyhow enough waffle!- on to my question... Up until now i've been using vectors to store various objects in the program such as Doors and Quads etc.. I learned recently that the Vector has in fact now been depreciated and the LinkedList has taken its place instead. Just wondering, what are the differences between the LinkedList and Vector? Does the LinkedList have any extended capabilites or is it just a Vector under a different guise? My main concern is about speed however, would I see any performance benefit by switching from Vectors to LinkedLists? I'm thinking about switching to the LinkedList- but if there is no point then i'll stick with what I have already.. Thanks for your help, Darragh
OrangyTang
OrangyTang
Vector has been depreciated, but its replacement is ArrayList. The only real difference being that ArrayList is unsyncronised (thread-unsafe) which means it can potentially be faster. If you do need a syncronised ArrayList you can use a thread safe wrapper (see the ArrayList javadocs).

ArrayList/Vector is basically a managed Object[] array, which handles resizing the array as needed, and doing inserts in the middle. During normal reading it should be as fast as a regular array.

LinkedList however is exactly that - a list made from a series of elements, each one linked to the next. Linked lists are a standard data structure, google should give you loads of info. In short, if you need lots of inserts/removes of objects at any point (particularly the head) a linked list would be better. If you just want an array that has a variable size ArrayList is better.

Generally, I use ArrayLists all over the place and linked lists rarely.
Darragh
Darragh
Cool.

Thanks for your help- that was just just the sort of answer I was looking for. Rating++ for you!

I think i'll implement the ArrayList then since most of my data is pretty much static and i'm not using threads...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.