根据文档:
报价第一:
Inserts the specified element at the front of this deque unless it would violate capacity restrictions. When using a capacity-restricted deque, this method is generally preferable to the addFirst(E) method, which can fail to insert an element only by throwing an exception.
这意味着如果您将 addFirst 与容量受限的双端队列一起使用,它可能会引发异常,但使用 offerFirst 不会引发任何异常。
报价最后
Inserts the specified element at the end of this deque unless it would violate capacity restrictions. When using a capacity-restricted deque, this method is generally preferable to the addLast(E) method, which can fail to insert an element only by throwing an exception.
同样,如果您将 addLast 与容量受限的双端队列一起使用,它可能会引发异常,但使用 offerLast 不会引发任何异常。