What is the right situation to use ArrayList over LinkedList? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the right situation to use ArrayList over LinkedList?

1st Dec 2016, 4:31 PM
Sami LASSED
Sami LASSED - avatar
3 Answers
2nd Dec 2016, 5:36 AM
Josias Oberholster
Josias Oberholster - avatar
+ 1
I don't want to read it more than I want to discuss it
7th Dec 2016, 3:26 PM
Sami LASSED
Sami LASSED - avatar
0
as far as I understand it, an arraylist does not guarantee an order and utilizes random access. This makes an arraylist fast and inexpensive, but removing an element will cause shifting. in the case of a large arraylist, this can become an expensive operation. whereas a linked list guarantees that it will keep the order the elements were added in. A linked list can also remove elements from the middle of the list without shifting, as the pointer can simply point to the next or previous object. A case to linked list over array list: performing multiple remove operations from a large list. Or if you want to keep all elements in the exact order you added them. Otherwise I would suggest using the arraylist. sorry for any typos or poor wording, I wrote this quickly on my phone.
24th Jan 2017, 9:55 PM
Erik Verduin
Erik Verduin - avatar