-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSortedSetDemo.java
More file actions
38 lines (31 loc) · 899 Bytes
/
Copy pathSortedSetDemo.java
File metadata and controls
38 lines (31 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package chapter17.six;
import java.util.Collections;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;
public class SortedSetDemo {
public static void main(String[] args) {
//ÅÅÐò¼¯ºÏ
SortedSet<String> sortedSet=new TreeSet<String>();
Collections.addAll(sortedSet, "one two three four five six".split(" "));//T... ºÜ¶à²ÎÊý
System.out.println(sortedSet);
String low=sortedSet.first();
String high=sortedSet.last();
System.out.println(low);
System.out.println(high);
Iterator<String> it=sortedSet.iterator();
for (int i = 0; i < 3; i++) {
if(i==2)
low=it.next();
if(i==3)
high=it.next();
else
it.next();
}
System.out.println(low);
System.out.println(high);
System.out.println(sortedSet.subSet(low, high));
System.out.println(sortedSet.headSet(high));
System.out.println(sortedSet.tailSet(low));
}
}