4:43 am - Tuesday April 25, 2017

LinkedList remove head elements to output using Poll() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This Program is used to remove head elements from LinkedList by using Poll() method.

Example Program


package com.example;

package com.example;

import java.util.*;

public class LinkedListPoll {
	public static void main(String[] args) // create a LinkedList

	{
		LinkedList list = new LinkedList(); // add some elements
		list.add("Hello");
		list.add(2);
		list.add("Chocolate");
		list.add("10");
		// print the list
		System.out.println("LinkedList:" + list); // retrieve and remove the
													// head of the list
		System.out.println("Head element of the list:" + list.poll()); // print
																		// the
																		// list
		System.out.println("LinkedList:" + list);
	}
}


 

output:

LinkedList:[Hello, 2, Chocolate, 10]
Head element of the list:Hello
LinkedList:[2, Chocolate, 10]

Declaration

Following is the declaration for java.util.LinkedList.poll() method

public E poll()

Parameters

  • NA

Return Value

This method returns the head of this list, or null if this list is empty

Exception

  • NA

BACK

Filed in: Java Examples

Comments are closed.