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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access