Monday, 12 May 2014

LinkedList : peekFirst : Get the Head of the List

public E peekFirst()
Retrieves, but does not remove, the first element of this list, or returns null if this list is empty.

import java.util.*;

class LinkedListPeekFirst{
 public static void main(String args[]){
  LinkedList<Integer> myList;
  myList = new LinkedList<> ();
  
  /* Add Elements to myList */
  myList.offerLast(10);
  myList.offerLast(20);
  myList.offerLast(30);
  myList.offerLast(40);
  
  System.out.print("Head of myList is ");
  System.out.println(myList.peekFirst());
 }
}

Output
Head of myList is 10

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment