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