同:二者都是向队列中添加元素
异:
总结:当队列容量超过限制时,add()会报异常,offer()会返回false
1. add()
API:
Inserts the specified element into this queue if it is possible to do soimmediately
without violating capacity restrictions, returning true upon success and throwing an
IllegalStateException if no space is currently available.
- capacity restrictions: 容量限制
- if no space is currently available: 当前没有可用空间
Return:
true (as specified by Collection.add)
Throws: IllegalStateException - if the element cannot be added at thistime due to capacity restrictions
2. offer()
API: