+ 2

What is the difference between arrayList and LinkedList?

15th Dec 2016, 5:35 PM
rathin
rathin - avatar
2 ответов
+ 4
An ArrayList object is basically an array. but you can use it like a list. the class ArrayList has an array containing your elements, if you add something the array is made bigger and if you remove something you can get this element anymore. LinkedList is a list where an element has a reference to the next element and the one before. so every element is linked to the next and the previous one. both classes implement the List interface, so if you just want to use a list both are usable. but there are some differences regarding speed and memory. ArrayList objects are faster in accessing elements (cause it's basically an array) but adding elements could be a bit slower (you need to copy every element into a new array). LinkedList objects could be slower, but adding elements or removing them is more memory efficient. (you don't have overhead because of array).
15th Dec 2016, 6:03 PM
Peter
0
Ed
2nd Feb 2017, 7:43 PM
Renier