0

I didn't actually get the thing - "ArrayList are for random access of data whereas LinkedList are for huge no of deletions and insertions".

Can't we use ArrayList for the same? If not then what also are the other limitations of it.

17th Mar 2016, 6:44 PM
Debdeep Ganguly
Debdeep Ganguly - avatar
2 Réponses
0
Basically the first is a contiguous implementation so the next element is placed in the adjacent memory so if you want to say access 5th element, you just add 5 to the base address of the current element. The second is a list in which the elements are spread out in the memory but every element contains link to the next element, so for accessing 5th, you'll have to go through all 5 elements in the list. However for insertion and deletion the first implementation will cause you to allocate the whole data structure to a new memory location in second case you can just change the links and add/delete the new single element. Just to add you can use ArrayLists but you should not for performance reasons as a LinkedList will be inherently faster.
19th Mar 2016, 12:52 AM
Pratul Kumar Singh
Pratul Kumar Singh - avatar
0
if the position of the elements doesn't matter, we can use any of them, but if the position is specific it is better to use LinkedList.
3rd Apr 2016, 8:44 PM
Rohith Reddy Vennam
Rohith Reddy Vennam - avatar