import java.util.SortedSet; import java.util.TreeSet; public class Test { public static void main(String[] args) { SortedSet<Integer> treeSet = new TreeSet<Integer>(); for (int i = 0; i < 10; i++) { treeSet.add(i); } System.out.println("第一个元素:" + treeSet.first()); System.out.println("最后一个元素:" + treeSet.last()); System.out.println("4前面的元素:" + treeSet.headSet(4)); System.out.println("6后面的元素:" + treeSet.tailSet(6)); System.out.println("2-8之间元素:" + treeSet.subSet(2, 8)); } }