Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList vs LinkedList !!

 
Gunjan Rathi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15484
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amir Alagic
Ranch Hand
Posts: 65
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This link is cool (also the links present inside the article).
 
raghu nagabandi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic