http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html#offer(E)
offer 来自Queue类
boolean offer(E e)
Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. When using a capacity-restricted queue, this method is generally preferable to add(E)
, which can fail to insert an element only by throwing an exception.
-
Parameters:
-
e
- the element to add
Returns:
- true if the element was added to this queue, else false Throws:
-
ClassCastException
- if the class of the specified element prevents it from being added to this queue -
NullPointerException
- if the specified element is null and this queue does not permit null elements -
IllegalArgumentException
- if some property of this element prevents it from being added to this queue
LinkedList类中的offer方法
public boolean offer(E e)
Adds the specified element as the tail (last element) of this list.
-
Specified by:
-
offer
in interfaceDeque<E>
Specified by:
-
offer
in interfaceQueue<E>
Parameters:
-
e
- the element to add
Returns:
-
true
(as specified byQueue.offer(E)
)
Since:
- 1.5
add方法 注意参数e是否可以是null
public boolean add(E e)
Appends the specified element to the end of this list.
This method is equivalent to addLast(E)
.
public E peek()
Retrieves, but does not remove, the head (first element) of this list.
poll
public E poll()
Retrieves and removes the head (first element) of this list.