5:22 pm - Sunday October 22, 2017

LinkedList Example Program for pollFirst()

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
/**
*@author: candidjava.com
*@description: codingĀ  for linked list poll method
*/
import java.util.LinkedList;

public class LinkedListDemo {

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]

BACK

Filed in: Z-A All Java Codes

Comments are closed.