How to traverse navigableSet in forward direction in java.

How to traverse navigableSet in forward direction in java.


Posted in : Java Posted on : December 6, 2010 at 6:19 PM Comments : [ 0 ]

How to traverse navigableSet in forward direction in java.

How to traverse navigableSet in forward direction in java.

Forward traversing means display elements of navigableSet into ascending order. Here, we will see how to display elements of navigableSet in ascending order in java. There is a method of java navigableSet interface called iterator() method. It returns a set iterator, that display element in ascending order.

Code:

ForwardTraverseNavigableSet.java

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

public class ForwardTraverseNavigableSet {
public static void main(String[] args) {
	NavigableSet obNavigableSet = new TreeSet();
	obNavigableSet.add(2);
	obNavigableSet.add(3);
	obNavigableSet.add(4);
	obNavigableSet.add(5);
	obNavigableSet.add(6);
	System.out.println("Forward traversing of navigableSet.");
	Iterator forward = obNavigableSet.iterator();
	while (forward.hasNext()) {
		System.out.println(forward.next());
	}
    }
}

Output:
Forward traversing of navigableSet.
2
3
4
5
6

Download this code.
Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics