Sunday 25 May 2014

LinkedList : pollLast : Retrieves and removes the last element of this list

public E pollLast()
Retrieves and removes the last element of this list. Return the last element of this list, or null if this list is empty.

import java.util.*;

class LinkedListPollLast{
 public static void main(String args[]){
  LinkedList<Integer> myList;
  myList = new LinkedList<> ();
  
  /* Add Elements to myList */
  myList.add(10);
  myList.add(20);
  myList.add(30);
  myList.add(40);
  
  System.out.println("Elements in myList are");
  System.out.println(myList);
  
  System.out.print("Last Element of myList is ");
  System.out.println(myList.pollLast());
  
  System.out.println("Elements in myList are");
  System.out.println(myList);
 }
}

Output
Elements in myList are
[10, 20, 30, 40]
Last Element of myList is 40
Elements in myList are
[10, 20, 30]


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment