两个方法都是获取列表的第一个元素
有什么区别?

解决方案 »

  1.   

     /**
         * 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();
        }
      

  2.   

    看到这个问题,我之前也不知道。但是我刚去看了LinkedList 类中两个方法的实现,
    public E element() {
            return getFirst();
    }
      

  3.   

    因为 LInkedList implements Deque<E>,
      

  4.   


    那element呢
      

  5.   


    那element呢
    Deque implement Queue,
    element 是Queue 接口里的方法