Java - If you are given a choice to use either ArrayList and LinkedList, Which one would you use and Why ?


ArrayList are implemented in memory as arrays and hence allows fast retrieval through indices but are costly if new elements are to be inserted in between other elements. 


LinkedList allows for constant-time insertions or removals using iterators, but only sequential access of elements 

1. Retrieval - If Elements are to be retrieved sequentially only, Linked List is preferred.


2. Insertion - If new Elements are to be inserted in between other elements , Array List is preferred.


3. Search - Binary Search and other optimized way of searching is not possible on Linked List.

4. Sorting - Initial sorting could be pain but lateral addition of elements in a sorted list is good with linked list.

5. Adding Elements - If sufficiently large elements needs to be added very frequently ,Linked List is preferable as elements don't need consecutive memory location.