About 31,700 results
Open links in new tab
  1. What is the difference between the add and offer methods in a Queue …

    In Java, the Queue interface provides two methods for adding elements to the queue: add(E e) and offer(E e). Both methods add the specified element to the queue if it is possible to do so immediately …

  2. java - Difference between add () and offer () methods of Queue ...

    What is the difference between these two methods? Queue.add - throws an exception if the operation fails, Queue.offer - returns a special value (either null or false, depending on the operation). Any …

  3. naming - Java Queues - why "poll" and "offer"? - Stack Overflow

    11 You're confusing Queue with Stack; push and pop are associated with the latter. Think of Queue in its proper producer/consumer context; poll and offer will make far more sense.

  4. Difference between offer() and add() in priority queue in java?

    Mar 23, 2013 · The two functions come from two different interfaces that PriorityQueue implements: add() comes from Collection. offer() comes from Queue. For a capacity-constrained queue, the …

  5. java - How do I use a PriorityQueue? - Stack Overflow

    Jul 11, 2017 · How do I get a PriorityQueue to sort on what I want it to sort on? Also, is there a difference between the offer and add methods?

  6. java - Difference between add (E e) and offer (E e) of ArrayDqueue ...

    5 The Queue documentation does a fairly good job of explaining the difference. add(E e) has the capability of throwing an exception if an element can't be added into the queue. This happens in …

  7. java - Enqueue/ Dequeue OR offer/ poll - Stack Overflow

    About offer and add: Well, that depends on how do you want to handle the failure of the insertion in the queue: The add method, which Queue inherits from Collection, inserts an element unless it would …

  8. java - LinkedBlockingQueue put vs offer - Stack Overflow

    Aug 15, 2016 · I have a linked blocking queue in which I am performing insertion and removal operations. I need to know which one is better put or offer in case of linked blocking queue. …

  9. java - Should Queue#offer () be preferred over Queue#add ()? Why ...

    offer() returns boolean whereas add() throws Exception if there are no elements in the Queue. So, which one should be used in general and what are the advantages of using one over the other?

  10. java - why do we have offer (E e) and offerLast (E e) methods in Deque ...

    Mar 22, 2018 · The Queue interface was added in Java 5. It defined the offer method, which adds an element at the end. (The offer method and the add method both return booleans. They differ in that …