MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

collectiontopics/SortedSetDemo.java:9–31  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

7
8public class SortedSetDemo {
9 public static void main(String[] args) {
10 SortedSet<String> sortedSet =
11 Arrays.stream(
12 "one two three four five six seven eight"
13 .split(" "))
14 .collect(toCollection(TreeSet::new));
15 System.out.println(sortedSet);
16 String low = sortedSet.first();
17 String high = sortedSet.last();
18 System.out.println(low);
19 System.out.println(high);
20 Iterator<String> it = sortedSet.iterator();
21 for(int i = 0; i <= 6; i++) {
22 if(i == 3) low = it.next();
23 if(i == 6) high = it.next();
24 else it.next();
25 }
26 System.out.println(low);
27 System.out.println(high);
28 System.out.println(sortedSet.subSet(low, high));
29 System.out.println(sortedSet.headSet(high));
30 System.out.println(sortedSet.tailSet(low));
31 }
32}
33/* Output:
34[eight, five, four, one, seven, six, three, two]

Callers

nothing calls this directly

Calls 5

splitMethod · 0.80
firstMethod · 0.80
nextMethod · 0.65
streamMethod · 0.45
iteratorMethod · 0.45

Tested by

no test coverage detected