• Post Reply Bookmark Topic Watch Topic
  • New Topic

LinkedList v/s ArrayList Usage  RSS feed

 
Vaibhav G Garg
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that ArrayList will be used where we are traversing the list and not doing insertion/deletion in middle of the list. But, if we need to do insertion/deletion in the middle of the list, then we should opt for Linkedlist. But, I find it hard to relate to some real time practical scenario in an application where we need to use a LinkedList. Can you please suggest some scenarios, where we will be doing insertion/deletion in the middle of the list. I feel that once the page is rendered at client side, then whatever operation is performed by user, it will be just like insert/update in a database, why there will be use of linkedlist in such a case?
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LinkedList works best in use cases where you need access elements in sequencial order (adding, removing and iterating).
For example - a Dropdown options. You want to show dropdown options in aplhabetical order. there, linkedlist shall be helpful
 
Vaibhav G Garg
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhay Agarwal wrote:LinkedList works best in use cases where you need access elements in sequencial order (adding, removing and iterating).
For example - a Dropdown options. You want to show dropdown options in aplhabetical order. there, linkedlist shall be helpful


Thanks Abhay for your reply. But, if we think the data is already sorted alphabatically on server side even if we use arraylist and then dropdown is displayed on the client side. So, what is the specific use of LinkedList here? May be I am missing something.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you ever need to look for a numbered element? If so, you need an array‑based List. Linked Lists are worthwhile if you want to insert or delete at the beginning or middle of the list. I presume (since this isn't “beginning”), that you are familiar with what it says in the Java Tutorials.
 
Paul Clapham
Sheriff
Posts: 22821
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And in real life, unless the bulk of your code is taken up by updating the list with thousands of changes, it won't make enough difference for you to notice. Just pick one and move on with more important things.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!