標籤:tin return ict returns empty 常用方法 which ddl using
定義
隊列是一種特殊的線性表,它只允許在表的前端進行刪除操作,而在表的後端進行插入操作。
LinkedList類實現了Queue介面,因此我們可以把LinkedList當成Queue來用
圖例
Queue本身是一種先入先出的模型(FIFO),和我們日常生活中的排隊模型很類似。根據不同的實現,他們主要有數組和鏈表兩種實現形式。如:
與隊列相關的類的關係圖如下:
常用方法
| 序號 |
方法名 |
描述 |
| 1 |
boolean add(E e) |
將指定的元素插入到隊列中。 |
| 2 |
Object element() |
檢索該隊列的頭。 |
| |
boolean offer(E e) |
將指定元素插入到該隊列中(在該隊列容量之內)。 |
| 3 |
Object peek() |
檢索該隊列的頭,如果該隊列為空白返回null。 |
| 4 |
Object poll() |
檢索並刪除該隊列的頭,如果該隊列為空白返回null。 |
| 5 |
Object remove() |
檢索並刪除該隊列的頭。 |
源碼
1 package java.util; 2 3 public interface Queue<E> extends Collection<E> { 4 /** 5 * Inserts the specified element into this queue if it is possible to do so 6 * immediately without violating capacity restrictions, returning 7 * {@code true} upon success and throwing an {@code IllegalStateException} 8 * if no space is currently available. 9 *10 * @param e the element to add11 * @return {@code true} (as specified by {@link Collection#add})12 * @throws IllegalStateException if the element cannot be added at this13 * time due to capacity restrictions14 * @throws ClassCastException if the class of the specified element15 * prevents it from being added to this queue16 * @throws NullPointerException if the specified element is null and17 * this queue does not permit null elements18 * @throws IllegalArgumentException if some property of this element19 * prevents it from being added to this queue20 */21 boolean add(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 * @param e the element to add31 * @return {@code true} if the element was added to this queue, else32 * {@code false}33 * @throws ClassCastException if the class of the specified element34 * prevents it from being added to this queue35 * @throws NullPointerException if the specified element is null and36 * this queue does not permit null elements37 * @throws IllegalArgumentException if some property of this element38 * prevents it from being added to this queue39 */40 boolean offer(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 * @return the head of this queue48 * @throws NoSuchElementException if this queue is empty49 */50 E remove();51 52 /**53 * Retrieves and removes the head of this queue,54 * or returns {@code null} if this queue is empty.55 *56 * @return the head of this queue, or {@code null} 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 * @return the head of this queue66 * @throws NoSuchElementException if this queue is empty67 */68 E element();69 70 /**71 * Retrieves, but does not remove, the head of this queue,72 * or returns {@code null} if this queue is empty.73 *74 * @return the head of this queue, or {@code null} if this queue is empty75 */76 E peek();77 }
參考:http://blog.csdn.net/u010617952/article/details/51726789
資料結構——java Queue類