天天看点

java.util.LinkedList<E>中offer和add的区别

offer

public boolean offer(E e)      

Adds the specified element as the tail (last element) of this list.

Specified by:

offer

 in interface 

Deque<E>

Specified by:

offer

 in interface 

Queue<E>

Parameters:

e

 - the element to add
Returns:

true

 (as specified by 

Queue.offer(E)

)

add

public boolean add(E e)      

Appends the specified element to the end of this list.

This method is equivalent to 

addLast(E)

.
Specified by:

add

 in interface 

Collection<E>

Specified by:

add

 in interface 

Deque<E>

Specified by:

add

 in interface 

List<E>

Specified by:

add

 in interface 

Queue<E>

Overrides:

add

 in class 

AbstractList<E>

Parameters:

e

 - element to be appended to this list
Returns:

true

 (as specified by 

Collection.add(E)

)
参考:https://docs.oracle.com/javase/7/docs/api/