File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Difference between ArrayList & LinkedList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Difference between ArrayList & LinkedList" Watch "Difference between ArrayList & LinkedList" New topic

Difference between ArrayList & LinkedList


Joined: May 25, 2006
Posts: 11
I need Difference between ArrayList & LinkedList.
Tell me the schenario which to use when?
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3640
1. What is the difference between a LinkedList and an ArrayList? Why would I use a LinkedList instead of an ArrayList?

ANSWER: a) A LinkedList is similar to an ArrayList in that it is ordered by index position, but it differs in that the elements are double-linked to one another. This linkage gives you new mehtods for adding and removing from the beginning or end.

b) If your program frequently provides random access to the data of the list, the ArrayList class offers quick access to individual elements of the list. This quick access comes at a cost of slower operations for adding and removing in the middle of the list. If this latter behavior is what you desire, than the LinkedList class offers a better alternative. It provides quick sequential access, additions, and deletes, at a cost of slower random access.


My blood is tested +ve for Java.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Please take the time to choose the correct forum for a question. This has nothing to do with JSP. Moved to Java in General (beginner).

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Difference between ArrayList & LinkedList
It's not a secret anymore!