Example of tailSet(E fromElement) method of navigaleSet interface in java.

Example of tailSet(E fromElement) method of navigaleSet interface in java.


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

Example of tailSet(E fromElement) method of navigaleSet interface in java.

Example of tailSet(E fromElement) method of navigaleSet interface in java.

In this example, you will see the implementation of tailSet(E fromElement) method. It returns a sortedset. The element in this set will be greater than or equal to the fromElement.

Code:

ExampleTailSet.java

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

public class ExampleTailSet {
	public static void main(String[] args) {
		NavigableSet obNavigableSet = new TreeSet();
		obNavigableSet.add("B");
		obNavigableSet.add("H");
		obNavigableSet.add("A");
		obNavigableSet.add("R");
		obNavigableSet.add("A");
		obNavigableSet.add("T");
		System.out.println("Elements of navigableSet.");
		Iterator iterator = obNavigableSet.iterator();
		while (iterator.hasNext()) {
			System.out.print(iterator.next() + " ");
		}
		SortedSet tailSortedSet = obNavigableSet.tailSet("B");
		Iterator tailItertor = tailSortedSet.iterator();
		System.out.println("\nElements of tail SortedSet.");
		while (tailItertor.hasNext()) {
			System.out.print(tailItertor.next() + " ");
		}
	}
}
Output:
Elements of navigableSet.
A B H R T
Elements of tail SortedSet.
B H R T

Download this code.
Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics