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) { NavigableSetOutput: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() + " "); } } }
Elements of navigableSet. A B H R T Elements of tail SortedSet. B H R T |
Download this code.
[ 0 ] Comments