Monday 12 May 2014

LinkedList : peekLast : Get Last Element of the List

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

import java.util.*;

class LinkedListPeekLast{
 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("Last Element of myList is ");
  System.out.println(myList.peekLast());
 }
}

Output
Last Element of myList is 40


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment