LinkedList Class
A linked list is a collection in which every object in the list maintains with it a pointer to the following object in the list and to the preceding object in the list. No array is involved at all in a linked list. Instead, the list is managed entirely by these pointers.
The LinkedList
class has several compelling advantages over the ArrayList
class:
Size issues: Because the ArrayList
class uses an internal array to store list data, the ArrayList
class frequently has to reallocate its array when you add items to the list. Linked lists don’t have any size issues. You can keep adding items to a linked list until your computer runs out of memory.
Inserting items: With the ArrayList
class, inserting an item in the middle of the list is inefficient because all items after the insertion point must be copied. With a LinkedList
class, though, inserting items in the middle of the list is much more efficient.
Removing items: With an array list, ...
Get Java For Dummies Quick Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.