wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Arrays Vs Linked List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays Vs Linked List" Watch "Arrays Vs Linked List" New topic
Author

Arrays Vs Linked List

vikram hegde
Greenhorn

Joined: Sep 07, 2005
Posts: 18
Hi Java Pals,

Can anyone put some light on, When to use Object[] and when to go for Linked list data structure? Here, Lets assume that the number of Objects to be inserted is known, i.e, let me know other criteria to be considered like performance, memory and any thing other than dynamic growing length property of Linked list over Arrays,in which length must be known at the time of instance creation of array.

with warm regards,
Vikram
luc comeau
Ranch Hand

Joined: Jan 20, 2005
Posts: 97
what if your numObjects is very large, and say you wanted to acess the last one in the list of objects, think of the time required to do so with a linked list, then with an array.
-just a small thought to try and help


National Research Council<br />Internet Logic Department
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Is that the only choice -- what about java.util.ArrayList? With the new generics enhancement to collections, I prefer collections like List<Foo> over Foo[], unless I know I must have an array -- perhaps other code is already expecting arrays.


There is no emoticon for what I am feeling!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Here's a Crib Sheet I made because I can't keep the pros & cons of all the collections in my head.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Mike Noel
Ranch Hand

Joined: Dec 15, 2005
Posts: 108
I would expect that the Java implementation of LinkedList hold a pointer to both the head and the tail of the list in order to make getLast fast. Actually, is the implemented LL a double-linked list?

I think the main advantage of a LL over and array is the ability to do fast inserts and deletes. With an array you have to shift elements when you insert or delete.

The crib sheet mentioned in the previous post points this out. I was just trying to mention that getLast() might be optimized.

_M_


Mike Noel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrays Vs Linked List