1 packagejava.util;2
3 public interface Queue extends Collection{4 /**
5 * Inserts the specified element into this queue if it is possible to do so6 * immediately without violating capacity restrictions, returning7 * {@codetrue} upon success and throwing an {@codeIllegalStateException}8 * if no space is currently available.9 *10 *@parame the element to add11 *@return{@codetrue} (as specified by {@linkCollection#add})12 *@throwsIllegalStateException if the element cannot be added at this13 * time due to capacity restrictions14 *@throwsClassCastException if the class of the specified element15 * prevents it from being added to this queue16 *@throwsNullPointerException if the specified element is null and17 * this queue does not permit null elements18 *@throwsIllegalArgumentException if some property of this element19 * prevents it from being added to this queue20 */
21 booleanadd(E e);22
23 /**
24 * Inserts the specified element into this queue if it is possible to do25 * so immediately without violating capacity restrictions.26 * When using a capacity-restricted queue, this method is generally27 * preferable to {@link#add}, which can fail to insert an element only28 * by throwing an exception.29 *30 *@parame the element to add31 *@return{@codetrue} if the element was added to this queue, else32 * {@codefalse}33 *@throwsClassCastException if the class of the specified element34 * prevents it from being added to this queue35 *@throwsNullPointerException if the specified element is null and36 * this queue does not permit null elements37 *@throwsIllegalArgumentException if some property of this element38 * prevents it from being added to this queue39 */
40 booleanoffer(E e);41
42 /**
43 * Retrieves and removes the head of this queue. This method differs44 * from {@link#poll poll} only in that it throws an exception if this45 * queue is empty.46 *47 *@returnthe head of this queue48 *@throwsNoSuchElementException if this queue is empty49 */
50 E remove();51
52 /**
53 * Retrieves and removes the head of this queue,54 * or returns {@codenull} if this queue is empty.55 *56 *@returnthe head of this queue, or {@codenull} if this queue is empty57 */
58 E poll();59
60 /**
61 * Retrieves, but does not remove, the head of this queue. This method62 * differs from {@link#peek peek} only in that it throws an exception63 * if this queue is empty.64 *65 *@returnthe head of this queue66 *@throwsNoSuchElementException if this queue is empty67 */
68 E element();69
70 /**
71 * Retrieves, but does not remove, the head of this queue,72 * or returns {@codenull} if this queue is empty.73 *74 *@returnthe head of this queue, or {@codenull} if this queue is empty75 */
76 E peek();77 }