offer(E e) Adds the specified element as the tail (last element) of this list. LikedList 通过继承,实现了接口 offer属于 offer in interface Deque<E>add 属于 add in interface Collection<E>都实现大概是为了 反射时使用的
add是list的 offer是queue的 api里说: add:Inserts the specified element at the specified position in this list 将指定的元素插入到list中指定的的位置。 offer:Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. 如果在不违反容量限制的情况下,尽可能快的将指定的元素插入到queue中去通地这个就可以看出区别了,哪个没有任何限制,哪个有限制
Adds the specified element as the tail (last element) of this list. LikedList 通过继承,实现了接口 offer属于 offer in interface Deque<E>add 属于 add in interface Collection<E>都实现大概是为了 反射时使用的
add当属于List
offer当属于queue吧
add当属于List
作为List使用时,一般采用add / get方法来 压入/获取对象
作为Queue使用时,才会采用 offer/poll/take等方法作为链表对象时,offer等方法相对来说没有什么意义
这些方法是用于支持队列应用的
offer是queue的
api里说:
add:Inserts the specified element at the specified position in this list
将指定的元素插入到list中指定的的位置。
offer:Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
如果在不违反容量限制的情况下,尽可能快的将指定的元素插入到queue中去通地这个就可以看出区别了,哪个没有任何限制,哪个有限制