查阅API文档,找到
add()
:增加一个元素。如果队列已满,则抛出一个IIIegaISlabEepeplian
异常
Inserts the specified element at the tail of this queue. As the queue is unbounded, this method will never throw IllegalStateException or return false.
offer()
:添加一个元素并返回true
。如果队列已满,则返回false
Inserts the specified element at the tail of this queue. As the queue is unbounded, this method will never return false.
分析
- 两者都是往队列尾部插入元素
- 当超出队列界限的时候,
add()
方法是抛出异常让你处理,而offer()
方法是直接返回false