How to Get the Tail from the TreeSet

From Java Example Source Code

Jump to: navigation, search

Contents

[edit] Overview - How to Get the Tail from the TreeSet

This Java example program shows how to get the tail from the TreeSet.

[edit] Java Source Code

  • Package: example.set
  • File: Tail.java
package example.set;
 
import java.util.Arrays;
import java.util.SortedSet;
import java.util.TreeSet;
 
public class Tail {
    public static void main(String args[]) throws Exception {
	String elements[] = { "Irish Setter", "Poodle", "English Setter", "Gordon Setter", "Pug" };
	SortedSet set = new TreeSet(Arrays.asList(elements));
	System.out.println(set.tailSet("Irish Setter"));
	System.out.println(set.headSet("Irish Setter"));
	System.out.println(set.headSet("Irish Setter\0"));
	System.out.println(set.tailSet("Irish Setter\0"));
	System.out.println(set.subSet("Irish Setter", "Poodle\0"));
	System.out.println(set.subSet("Irish Setter", "Irish Setter\0"));
	System.out.println(set.subSet("Irish Setter", "Irish Setter"));
    }
}

[edit] What Result You Can Get

Run the program, you will get:

[Irish Setter, Poodle, Pug]
[English Setter, Gordon Setter]
[English Setter, Gordon Setter, Irish Setter]
[Poodle, Pug]
[Irish Setter, Poodle]
[Irish Setter]
[]

[edit] Required External Libraries and/or Files for this Java Example

Need nothing.


[edit] How to Run this Java Example Program

We recommend running this Java example program with Eclipse.

For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.

It's fairly easy.



[edit] Question & Answer

Any question?

Click edit and post your question or answer here.


Personal tools