When to use an Array vs. LinkedList vs. ArrayList ?

When should I use one as opposed to another? I know Linked/ArrayLists provide methods for functionality such as .add() .remove() etc

26th Dec 2016, 8:23 PM
Justin - avatar
3 Answers
+ 5
see, when you know the number of elements you will be requiring than use Array, a fixed memory space would be assigned, but now you cannot decrease or increase its size. Now if you are not sure that how many elements you would enter you could use ArrayList with it you can increase or decrease your array size by adding or removing elements. Same is the case with LinkedList. Now for choosing between ArrayList and LinkedList, when there are more number of insertions and deletions one should use LinkedList whereas when there is a need for faster access to the data one should use ArrayList.
1st Jan 2017, 5:06 PM
Sawan Kalra
Sawan Kalra - avatar
+ 1
If you want to dynamically add elements or add elements at the middle of the list too often,use linked list If you know the amount of memory you need for your data and access by index, use array
26th Dec 2016, 9:18 PM
Jawwad Hossain
Jawwad Hossain - avatar
Makes sense. So if I have a fixed (Wont be changed in the future) amount, use an array. , but if the amount is subject to change, use an ArrayList or LinkedList ? Thank You !
26th Dec 2016, 9:52 PM
Justin - avatar