Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit921555f

Browse files
committed
Compare User define class in TreeSet
1 parentc9105fb commit921555f

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

‎Collection/15_TreeSet.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ public static void main(String[] args) {
5151

5252
// 12) public E higher(E);
5353
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();
5558
System.out.println(ts.pollFirst());
5659
System.out.println(ts);
5760

58-
//14) public E pollLast()
61+
//15) public E pollLast()
5962
System.out.println(ts.pollLast());
6063
System.out.println(ts);
6164
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
importjava.util.*;
2+
3+
classCricPlayerimplementsComparable {
4+
5+
Stringname =null;
6+
CricPlayer(Stringname) {
7+
8+
this.name =name;
9+
}
10+
11+
publicintcompareTo(Objectobj) {
12+
13+
returnthis.name.compareTo(((CricPlayer)obj).name);
14+
}
15+
16+
publicStringtoString() {
17+
18+
returnname;
19+
}
20+
}
21+
classTreeSetDemo {
22+
23+
publicstaticvoidmain(String[]args) {
24+
25+
TreeSetts =newTreeSet();
26+
27+
ts.add(newCricPlayer("Rohit"));
28+
ts.add(newCricPlayer("Virat"));
29+
ts.add(newCricPlayer("MSD"));
30+
ts.add(newCricPlayer("MSD"));
31+
ts.add(newCricPlayer("Surya"));
32+
ts.add(newCricPlayer("Tilak"));
33+
ts.add(newCricPlayer("Tilak"));
34+
ts.add(newCricPlayer("Ishan"));
35+
36+
System.out.println(ts);
37+
}
38+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp