/** * 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(); }
看到这个问题,我之前也不知道。但是我刚去看了LinkedList 类中两个方法的实现, public E element() { return getFirst(); }
因为 LInkedList implements Deque<E>,
那element呢
那element呢 Deque implement Queue, element 是Queue 接口里的方法
* 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();
}
public E element() {
return getFirst();
}
那element呢
那element呢
Deque implement Queue,
element 是Queue 接口里的方法