Get Head Set from TreeSet in Java
Description
The following code shows how to get Head Set from TreeSet.
Example
//from w w w. jav a2s . com
import java.util.SortedSet;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
TreeSet<String> tSet = new TreeSet<String>();
tSet.add("1");
tSet.add("2");
tSet.add("3");
tSet.add("4");
tSet.add("5");
SortedSet sortedSet = tSet.headSet("3");
System.out.println("Head Set Contains : " + sortedSet);
}
}
The code above generates the following result.