Monday, 16 January 2017

LinkedList : PollMethod





import java.util.Iterator;
import java.util.LinkedList;

public class PollMethod {

public static void main(String[] args) {
// TODO Auto-generated method stub


LinkedList<String> ll1 = new LinkedList<>();

ll1.add("One");
ll1.add("Two");
ll1.add("Three");
ll1.add("Four");
ll1.add("Five");
ll1.add("Two");
ll1.add("Three");
ll1.add("Four");

System.out.print("Full-List : "+ll1);

System.out.print("\n Get top element  : ");
System.out.println(ll1.poll());

System.out.print("\n Get first element  : ");
System.out.println(ll1.pollFirst());

System.out.print("\n Get last element  : ");
System.out.println(ll1.pollLast());

System.out.print("Full-List : "+ll1);

}
}

No comments:

Post a Comment