Use of pollFirst() method of java navigableSet interface.

Use of pollFirst() method of java navigableSet interface.


Posted in : Core Java Posted on : December 7, 2010 at 4:52 PM Comments : [ 0 ]

Use of pollFirst() method of java navigableSet interface.

Use of pollFirst() method of java navigableSet interface.

In this example, you will see the implementation of pollFirst() method of java. It removes first elements of this set. If there is no any element in this set it returns null.

Code:

ExamplePollFirst.java

import java.util.Iterator;
import java.util.NavigableSet;
import java.util.TreeSet;

public class ExamplePollFirst {
public static void main(String[] args) {
	NavigableSet obSet = new TreeSet();
	obSet.add(2);
	obSet.add(3);
	obSet.add(4);
	obSet.add(5);
	obSet.add(6);
	Iterator obIterator = obSet.iterator();
	System.out.println("Elements of navigableset.");
	while (obIterator.hasNext()) {
		System.out.print(obIterator.next() + " ");
	}
	obSet.pollFirst();
	Iterator obIterator2 = obSet.iterator();
	System.out.println("\nElement of set after using pollFirst method.");
	while (obIterator2.hasNext()) {
		System.out.print(obIterator2.next() + " ");
	}
   }
}
Output:
Elements of navigableset.
2 3 4 5 6
Element of set after using pollFirst method.
3 4 5 6

Download this code.
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics