Peek the element

ReturnMethodSummary
Eelement()Retrieves, but does not remove, the head (first element) of this list.
Epeek()Retrieves, but does not remove, the head (first element) of this list.
EpeekFirst()Retrieves, but does not remove, the first element of this list, or returns null if this list is empty.
EpeekLast()Retrieves, but does not remove, the last element of this list, or returns null if this list is empty.

  import java.util.LinkedList;
import java.util.ListIterator;

public class Main{
    public static void main(String args[]) {
        LinkedList<String> ll = new LinkedList<String>();

        ll.add("A");
        ll.add("ja v a2s.com");
        ll.add("B");
        ll.add("C");


        System.out.println(ll.element());
        System.out.println(ll.peek());
        System.out.println(ll.peekFirst());
        System.out.println(ll.peekLast());

    }
}
  

The output:


A
A
A
C
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.