Java Reference
In-Depth Information
Display 15.5
Adding a Node at the Start
new Node("beer", 6, head)
creates this node and positions
it here.
"beer"
6
head
new Node("beer", 6, head)
moves head to the new node.
"rolls"
10
"jam"
3
"milk"
1
"tea"
2
null
This removes the first node from the linked list and leaves the linked list one node
shorter. But what happens to the deleted node? At some point, Java will automatically
collect it, along with any other nodes that are no longer accessible, and recycle the
memory they occupy. This is known as automatic garbage collection .
Display 15.6 contains a simple program that demonstrates how some of the methods
in the class LinkedList1 behave.
automatic
garbage
collection
 
 
Search WWH ::




Custom Search