By candid | Posted :
Jun 30, 2015
| Updated :
Jun 30, 2015
Retrieves and removes the last element of this list, or returns null if this list is empty.
Program
package com.candidjava;
import java.util.LinkedList;
/**
*
* @author : mohan
* @description :The java.util.LinkedList.pollLast() method retrieves and
* removes the last element of this list, or returns null if this
* list is empty.
*/
public class LinkedListPollLast {
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.add("anandh");
list.add("hari");
list.add("vinoth");
list.add("mohan");
list.add("kamal");
System.out.println("LinkedList:" + list);
System.out.println("Last element of the list:" + list.pollLast());
System.out.println("LinkedList:" + list);
}
}
Output
LinkedList:[anandh, hari, vinoth, mohan, kamal]
Last element of the list:kamal
LinkedList:[anandh, hari, vinoth, mohan]
Explanation
public E pollLast()
Retrieves and removes the last element of this list, or returns null if this list is empty.
Specified by:
pollLast in interface Deque<E>
Returns:
the last element of this list, or null if this list is empty