Remove/poll, Add/offer, element/peek differences in Java queue

Source: Internet
Author: User

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 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

Remove/poll, Add/offer, element/peek differences in Java queue

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.