0

What is differences between #Arraylist and #Linkedlist in java?

What's the differences between this both in working and usefulness, when we should use arraylist and when should use linkedlist Use Simple english word please :D Thanks😍😍

18th Jan 2020, 10:15 PM
Hedi Muhamad
Hedi Muhamad - avatar
2 Answers
+ 1
ArrayList organized as array and every element of it have unique number. So, the task of get some certain element will be executed very quickly because JVM knows the position of element by its number. In LinkedList elements have not any numbers, it have a LINKS to next element and this task will be executed by iterate ALL THE LIST from top of list to searching element. And it will be more slowly. But task of putting some element in the middle of list will be executed in ArrayList slowly because JVM will be assign a new numbers (+1) for all elements after that element. In LinkedList this task will be executed by creating of two new links: in this element to next and in previous element to this. In nutshell: AL-ArrayList, LL-LinkedList get() - AL fast, LL slow set() - AL fast, LL slow add() - AL fast, LL fast add(int i, value) - AL slow, LL fast remove () - AL slow, LL fast.
10th Jul 2020, 12:32 PM
Knyazev Aleksey
Knyazev Aleksey - avatar
+ 1
Knyazev Aleksey Thanks bro. Nice example.❀
10th Jul 2020, 1:03 PM
Hedi Muhamad
Hedi Muhamad - avatar