Java Reference
In-Depth Information
"peach", "plum",
"turnip", "onion", "nectarine"
};
System.out.println("array
size
=
"+fruitAndVeg.length);
for (String fruitVeg: fruitAndVeg)
sss.add(fruitVeg);
dump("sss:", sss);
System.out.println("sorted set size = "+sss.size());
System.out.println("first element = "+sss.first());
System.out.println("last element = "+sss.last());
System.out.println("comparator
=
"+sss.comparator());
dump("hs:", sss.headSet("n"));
dump("ts:", sss.tailSet("n"));
System.out.println("count of p-named fruits & veget-
ables = "+
sss.subSet("p", "q").size());
System.out.println("incorrect count of c-named fruits
& vegetables = "+
sss.subSet("carrot",
"cucum-
ber").size());
System.out.println("correct count of c-named fruits &
vegetables = "+
sss.subSet("carrot",
"cucum-
ber\0").size());
}
static void dump(String title, SortedSet<String> sss)
{
System.out.print(title+" ");
for (String s: sss)
System.out.print(s+" ");
System.out.println();
}
}
When you run this application, it generates the following output:
Search WWH ::




Custom Search