By candid | Posted :
Jun 26, 2015
| Updated :
Jun 26, 2015
Retrieves and removes the head (first element) of this list.
Program
package com.candidjava;
import java.util.LinkedList;
/**
*
* @author : mohan
* @description :The java.util.LinkedList.poll() method retrieves and removes
* the head (first element) of this list
*/
public class LinkedListPoll {
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("Head element of the list:" + list.poll());
System.out.println("LinkedList:" + list);
}
}
Output
LinkedList:[anandh, hari, vinoth, mohan, kamal]
Head element of the list:anandh
LinkedList:[hari, vinoth, mohan, kamal]
Explanation
public E poll()
Retrieves and removes the head (first element) of this list.
Specified by:
poll in interface Deque<E>
Specified by:
poll in interface Queue<E>
Returns:
the head of this list, or null if this list is empty