Java LinkedList poll Example
LinkedList class poll method example. This example shows you how to use poll method.
LinkedList class poll method example. public LinkedList poll() Retrieves and removes the head (first element) of this list
Here is the code
/**
* @ # Poll.java
* A class repersenting use to poll method of LinkedList class in java.util package
* version 15 May 2008
* author Rose India
*/
import java.util.*;
public class Poll {
public static void main(String args[]) {
LinkedList list = new LinkedList();
int i = 11;
String str = "Rose";
//Add the specified element to the end of this list.
list.add(i);
list.add(str);
//Remove and display first element
System.out.println("Remove element = " + list.poll());
System.out.println("list = " + list);
}
} |
Output
Remove element = 11
list = [Rose] |
|