public Object dequeue() throws QueueEmptyException { Object obj; if (size == 0) throw new QueueEmptyException("Queue is empty."); obj = head.getElement(); head = head.getNext(); size--; if (size == 0) tail = null; // the queue is now empty return obj; }