Grokking Java Interview Questions
0% completed
ArrayList vs LinkedList
An online grocery store keeps 100,000 order ids, from 1001 to 101000, in one list, and the code reads one of them with orders.get(50000). If orders is an ArrayList, the call reads one slot of an array. If orders is a LinkedList, the same call follows 49,999 references from one element to the next.
Both classes implement List, and both calls return 51001. The four questions below explain the difference: how a LinkedList stores its elements, what each operation costs in the two lists, why the ArrayList usually does less work, and where a LinkedList remains a fair choice.
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%