In addition to some of the collection classes in Java, actually implemented a number of interfaces, so there will be a variety of methods for the same operation, such as the LinkedList class.
First look at the inheritance diagram for the Java Collection class:
Here is a simple way to make a simple distinction between its repeated methods.
Offer,add differences:
Some queues have a size limit, so if you want to add a new item to a full queue, the extra items will be rejected.
At this point the new offer method will work. It does not throw a unchecked exception to the call to the Add () method, but only gets the false returned by the offer ().
Poll,remove differences:
Both the Remove () and poll () methods remove the first element (head) from the queue. Remove () behaves like the version of the Collection interface,
However, the new poll () method does not throw an exception when called with an empty collection, only returns NULL. Therefore, the new method is more suitable for situations prone to abnormal conditions.
Peek,element differences:
Element () and peek () are used to query the elements on the head of the queue. Similar to the Remove () method, Element () throws an exception when the queue is empty, and peek () returns NULL.
The differences between the various methods of the Java Queue