Friday, 15 April 2011

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


Hi, I used to add and present my element in the final speed. Both booleans are returning and both do not throw exception except the NPE.

  public class Arrayedemmo {public static zero main (string [] args) {// Make arrendek element. ArrayDeque & LT; Integer & gt; Deck = new ArrayDek & lt; & Gt; (); Deque.add (10); Deque.offer (30);   

> Add and add both public zeros (EE) {if (e == blank) throw new NullPointerException (); Element [tail] = e; If ((tail = (tail + 1) & amp; (elements. Length - 1)) == head) Double capacity (); }

Two methods are equivalent.

The reason for this is that both of them are present which both specify.

Both the java.util.Queue specifies that the implementation of the java.util.Queue has been allowed to enforce capacity restrictions , And has been specified in two ways to behave differently in this matter so that the element would violate that restriction; Specifically, addition (...) in that case is specified for throwing the invalidstate exception , while the proposal (...) returns false .

java.util.ArrayDequeue , however, does not impose any capacity restriction, so this condition does not occur with it, so the distinction does not apply.


No comments:

Post a Comment