LinkedList E pollFirst() method Example Program


Retrieves and removes the first 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.pollFirst() method retrieves and
 *              removes the first element of this list, or returns null if this
 *              list is empty.
 */
public class LinkedListPollFirst {
	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("First element of the list:" + list.pollFirst());
		System.out.println("LinkedList:" + list);
	}
}

Output

LinkedList:[anandh, hari, vinoth, mohan, kamal]
First element of the list:anandh
LinkedList:[hari, vinoth, mohan, kamal]

Explanation

public E pollFirst()
Retrieves and removes the first element of this list, or returns null if this list is empty.

Specified by:
pollFirst in interface Deque<E>

Returns:
the first element of this list, or null if this list is empty

Since:
1.6


Related Post

Comments


©candidjava.com