Queue 方法
-
- /**
- * Retrieves, but does not remove, the head (first element) of this list.
- *
- * @return the head of this list, or {@code null} if this list is empty
- * @since 1.5
- */
- public E peek() {
- final Node<E> f = first;
- return (f == null) ? null : f.item;
- }
- /**
- * Retrieves, but does not remove, the head (first element) of this list.
- *
- * @return the head of this list
- * @throws NoSuchElementException if this list is empty
- * @since 1.5
- */
- public E element() {
- return getFirst();
- }
- /**
- * Retrieves and removes the head (first element) of this list.
- *
- * @return the head of this list, or {@code null} if this list is empty
- * @since 1.5
- */
- public E poll() {
- final Node<E> f = first;
- return (f == null) ? null : unlinkFirst(f);
- }
- /**
- * Retrieves and removes the head (first element) of this list.
- *
- * @return the head of this list
- * @throws NoSuchElementException if this list is empty
- * @since 1.5
- */
- public E remove() {
- return removeFirst();
- }
- /**
- * Adds the specified element as the tail (last element) of this list.
- *
- * @param e the element to add
- * @return {@code true} (as specified by {@link Queue#offer})
- * @since 1.5
- */
- public boolean offer(E e) {
- return add(e);
- }
复制代码
------
原文链接:https://pdai.tech/md/java/collection/java-collection-LinkedList.html
|