File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -51,11 +51,14 @@ public static void main(String[] args) {
51
51
52
52
// 12) public E higher(E);
53
53
System .out .println (ts .higher ("Ashish" ));
54
- // 13) public E pollFirst();
54
+
55
+ // 13) public java.util.NavigableSet<E> descendingSet();
56
+ System .out .println (ts .descendingSet ());
57
+ // 14) public E pollFirst();
55
58
System .out .println (ts .pollFirst ());
56
59
System .out .println (ts );
57
60
58
- // 14 ) public E pollLast()
61
+ // 15 ) public E pollLast()
59
62
System .out .println (ts .pollLast ());
60
63
System .out .println (ts );
61
64
}
Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+
3
+ class CricPlayer implements Comparable {
4
+
5
+ String name = null ;
6
+ CricPlayer (String name ) {
7
+
8
+ this .name = name ;
9
+ }
10
+
11
+ public int compareTo (Object obj ) {
12
+
13
+ return this .name .compareTo (((CricPlayer )obj ).name );
14
+ }
15
+
16
+ public String toString () {
17
+
18
+ return name ;
19
+ }
20
+ }
21
+ class TreeSetDemo {
22
+
23
+ public static void main (String [] args ) {
24
+
25
+ TreeSet ts = new TreeSet ();
26
+
27
+ ts .add (new CricPlayer ("Rohit" ));
28
+ ts .add (new CricPlayer ("Virat" ));
29
+ ts .add (new CricPlayer ("MSD" ));
30
+ ts .add (new CricPlayer ("MSD" ));
31
+ ts .add (new CricPlayer ("Surya" ));
32
+ ts .add (new CricPlayer ("Tilak" ));
33
+ ts .add (new CricPlayer ("Tilak" ));
34
+ ts .add (new CricPlayer ("Ishan" ));
35
+
36
+ System .out .println (ts );
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments