As we can see from the above result, peek always returns the first value and in the end, the queue still contains all the three elements inserted.
The element() method behaves like peek(), so it again retrieves the value of the first element without removing it. Unlike peek(), however, if the list is empty element() throws a NoSuchElementException.
The poll() method retrieves the value of the first element of the queue by removing it from the queue. At each invocation, it removes the first element of the list and if the list is already empty it returns null but does not throw an exception.
As we can see from the following result, the first two invocations of poll () remove the two elements of the list that is now empty. The third poll() call returns null, without throwing no exception and the list at the end does not contain any element.
The remove() method behaves as the poll() method, so it removes the first element of the list and if the list is empty it throws a NoSuchElementException.