/*Remove and retrieve the head of the list using poll() and class Poll*/
/**
*@Author: candidjava.com
*@Description: Remove and retrieve the head of the list using poll() and class Poll
*/
import java.util.*;
public class LinkedListPoll {
public static void main(String args[])
{
LinkedList<String> ls=new LinkedList<String> ();//create ls object for LinkedList
ls.add("welcome");//add content to the ls
ls.add("to");//add content to the ls
ls.add("chennai");//add content to the ls
System.out.println("linkedlist:"+ls);
System.out.println("remove head ele of the list:"+ls.poll());/*remove and retrives the head of the list*/
System.out.println("linkedlist:"+ls);
}
}

Output:

linkedlist:[welcome,to,chennai]
remove head ele of the list:welcome
linkedlist:[to,chennai]