import java.util.Arrays;
import java.util.SortedSet;
import java.util.TreeSet;
/*
n o w j a v a . c o m 提供
*/
public class Main
{
public static void main(String[] args)
{
// create TreeSet from array colors
String[] colors = {"yellow", "green", "black", "tan", "grey",
"white", "orange", "red", "green"};
SortedSet<String> tree = new TreeSet<>(Arrays.asList(colors));
/*
*来 自
n o w j a v a . c o m
*/
System.out.print("sorted set: ");
printSet(tree);
// get headSet based on "orange"
System.out.print("headSet (\"orange\"): ");
printSet(tree.headSet("orange"));
// get tailSet based upon "orange"
System.out.print("tailSet (\"orange\"): ");
printSet(tree.tailSet("orange"));
// get first and last elements
System.out.printf("first: %s%n", tree.first());
System.out.printf("last : %s%n", tree.last());
}
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。