aspose file tools*
The moose likes Java in General and the fly likes ArrayList vs LinkedList !! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ArrayList vs LinkedList !!" Watch "ArrayList vs LinkedList !!" New topic
Author

ArrayList vs LinkedList !!

Gunjan Rathi
Greenhorn

Joined: Jul 19, 2006
Posts: 4
What are the differences between an ArrayList and a LinkedList ?
Where do we use ArrayList and where LinkedList ?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

ArrayList is implemented with an array to store the elements of the list. LinkedList is implemented as a doubly-linked list.

Which one you should use depends on how you use the list. An ArrayList is faster when you need to lookup an element at a known index in the list, but slower when you insert elements in the list. A LinkedList is slower when looking up an element at a known index in the list, but faster when you insert elements in the list.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Adding on top of what Jesper said, both of them are collections and used to deal with a heterogeneous elements in a sequence.

As they follow different implementation strategies, they have different characteristics. I think Jesper have given a good explanation on that.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Amir Alagic
Ranch Hand

Joined: Mar 21, 2006
Posts: 65
http://narencoolgeek.blogspot.com/2006/09/arraylist-vs-linkedlist.html
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344



This link is cool (also the links present inside the article).
raghu nagabandi
Ranch Hand

Joined: Aug 14, 2007
Posts: 35
ArryList: we will use ArrayList in following cases
if the requirement contains more retrival operation then we have to use ArrayList

LinkedList: If the requirement contains more insertions and deletions then we will use LinkedList
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by raghu nagabandi:
ArryList: we will use ArrayList in following cases
if the requirement contains more retrival operation then we have to use ArrayList


Only for random access. If we always iterate through all elements of a list in order, a LinkedList should be just fine (although still a little bit slower).


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
Don't get me started about those stupid light bulbs.
 
subject: ArrayList vs LinkedList !!
 
Similar Threads
Difference between ArrayList and LinkedList?
HashSet question
iterating over a LinkedList or ArrayList
What is the difference between LinkedList and ArrayList ?
LinkedList and ArrayList