Java Reference
In-Depth Information
ingsortedsetismodified.Asaresult,aset-basedrangeviewcanbeusedforalengthy
period of time.
Note Unlike a list-based range view whose endpoints are elements in the backing
list, the endpoints of a set-based range view are absolute points in element space, al-
lowingaset-basedrangeviewtoserveasawindowontoaportionoftheset'selement
space.Anychangesmadetotheset-basedrangeviewarewrittenbacktothebacking
sorted set and vice versa.
Eachrangeviewreturnedby headSet() , subSet() ,or tailSet() is half open
becauseitdoesnotincludeitshighendpoint( headSet() and subSet() )oritslow
endpoint ( tailSet() ). For the first two methods, the high endpoint is specified by
argument toElement ;forthelastmethod,thelowendpointisspecifiedbyargument
fromElement .
Note Youcouldalsoregardthereturnedrangeviewasbeing half closed becauseit
includes only one of its endpoints.
Listing 5-9 demonstrates a sorted set based on a tree set.
Listing 5-9. A sorted set of fruit and vegetable names
import java.util.SortedSet;
import java.util.TreeSet;
class SortedSetDemo
{
public static void main(String[] args)
{
SortedSet<String> sss = new TreeSet<>();
String[] fruitAndVeg =
{
"apple", "potato", "turnip", "banana", "corn",
"carrot", "cherry",
"pear",
"mango",
"strawberry",
"cucumber",
"grape", "banana",
"kiwi", "radish", "blueberry", "tomato", "onion",
"raspberry",
"lemon", "pepper", "squash", "melon", "zucchini",
 
Search WWH ::




Custom Search