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中去
通地这个就可以看出区别了,哪个没有任何限制,哪个有限制
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中去
通地这个就可以看出区别了,哪个没有任何限制,哪个有限制
本文解释了Java集合框架中List的add方法与Queue的offer方法之间的关键区别。add方法用于将指定元素插入到List中的指定位置,而offer方法则是在不违反容量限制的前提下尽可能快地将元素插入到Queue中。

4773

被折叠的 条评论
为什么被折叠?



