Java Collection Tutorial - Java SortedSet.tailSet(E fromElement)








Syntax

SortedSet.tailSet(E fromElement) has the following syntax.

SortedSet < E > tailSet(E fromElement)

Example

In the following code shows how to use SortedSet.tailSet(E fromElement) method.

import java.util.Arrays;
import java.util.SortedSet;
import java.util.TreeSet;
//from  w  w  w  . j  a va  2  s. c  om
public class Main {
  public static void main(String args[]) throws Exception {
    String elements[] = { "I", "P", "E", "G", "P" };
    SortedSet set = new TreeSet(Arrays.asList(elements));
    System.out.println(set.tailSet("I"));
    System.out.println(set.headSet("I"));
    System.out.println(set.headSet("I\0"));
    System.out.println(set.tailSet("I\0"));
    System.out.println(set.subSet("I", "P\0"));
    System.out.println(set.subSet("I", "I\0"));
    System.out.println(set.subSet("I", "I"));
  }
}

The code above generates the following result.