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😍😍
2 Réponses
+ 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.
+ 1
Knyazev Aleksey
Thanks bro.
Nice example.❤