-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeSet
More file actions
42 lines (29 loc) · 712 Bytes
/
TreeSet
File metadata and controls
42 lines (29 loc) · 712 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
39
40
41
42
package Collections;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;
public class Treeset {
public static void main(String[] args) {
TreeSet<Integer> h = new TreeSet<Integer>();
h.add(1);
h.add(2);
h.add(3);
h.add(4);
h.add(5);
h.add(9);
h.add(10);
h.add(10);
// Collections.sort(h);
Iterator<Integer> itr = h.iterator();
while(itr.hasNext()) {
System.out.print(itr.next()+" ");
}
//System.out.println("Lowest value"+ h.pollFirst());
// System.out.println("Highest value "+h.pollLast());
System.out.println();
Iterator<Integer> itr1 = h.descendingIterator();
while(itr1.hasNext()) {
System.out.print(itr1.next()+" ");
}
}
}