LinkedList.javaAPI DocExample4834Sat Jun 02 02:42:14 BST 2001None


public class LinkedList extends Object
This class implements a linked list that can contain any type of object that implements the nested Linkable interface. Note that the methods are all synchronized, so that it can safely be used by multiple threads at the same time.

Fields Summary
This is the only field of the class. It holds the head of the list
Constructors Summary
Methods Summary
public synchronized LinkedList$LinkablegetHead()
Return the first node in the list

 return head; 
public synchronized voidinsertAtHead(LinkedList$Linkable node)
Insert a node at the beginning of the list

    head = node;
public synchronized voidinsertAtTail(LinkedList$Linkable node)
Insert a node at the end of the list

    if (head == null) head = node;
    else {
      Linkable p, q;
      for(p = head; (q = p.getNext()) != null; p = q);
public synchronized voidremove(LinkedList$Linkable node)
Remove a node matching the specified node from the list. Use equals() instead of == to test for a matched node.

    if (head == null) return;
    if (node.equals(head)) { 
      head = head.getNext(); 
    Linkable p = head, q = null;
    while((q = p.getNext()) != null) {
      if (node.equals(q)) {
      p = q;
public synchronized LinkedList$LinkableremoveFromHead()
Remove and return the node at the head of the list

    Linkable node = head;
    if (node != null) {
      head = node.getNext();
    return node;
public synchronized LinkedList$LinkableremoveFromTail()
Remove and return the node at the end of the list

    if (head == null) return null;
    Linkable p = head, q = null, next = head.getNext();
    if (next == null) {
      head = null;
      return p;
    while((next = p.getNext()) != null) { 
      q = p; 
      p = next;
    return p;