Tail set, header set and sub set


import java.util.Arrays;
import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
    public static void main(String args[]) throws Exception {
        String elements[] = { "a", "b", "c","d", "e" };
        SortedSet set = new TreeSet(Arrays.asList(elements));
        System.out.println(set.tailSet("c"));
        System.out.println(set.headSet("d"));
        System.out.println(set.headSet(""));
        System.out.println(set.subSet("b", "d"));
    }
}

Output:


[c, d, e]
[a, b, c]
[]
[b, c]
Home 
  Java Book 
    Runnable examples  

Collection TreeSet:
  1. TreeSet is a sorted set(SortedSet)
  2. First in a TreeSet
  3. Head Set from TreeSet
  4. Higher and lower set
  5. Last from a Set
  6. Reverse order a TreeSet
  7. Tail set, header set and sub set