File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ //version 11.1
2
+
3
+ //uses Comparator
4
+
5
+ import java .util .*;
6
+
7
+ class MarksSort implements Comparator
8
+ {
9
+ public int compare (Object ob1 ,Object ob2 )
10
+ {
11
+ Student st1 =(Student )ob1 ;
12
+ Student st2 =(Student )ob2 ;
13
+ return (st1 .marks - st2 .marks );
14
+ }
15
+ }
16
+ class RollnoSort implements Comparator
17
+ {
18
+ public int compare (Object ob1 , Object ob2 )
19
+ {
20
+ Student st1 =(Student )ob1 ;
21
+ Student st2 =(Student )ob2 ;
22
+ return (st1 .rollno - st2 .rollno );
23
+ }
24
+ }
25
+ class Student
26
+ {
27
+ int rollno ,marks ;
28
+ String name ;
29
+ Student (String name ,int rollno , int marks )
30
+ {
31
+ this .name =name ;
32
+ this .rollno =rollno ;
33
+ this .marks =marks ;
34
+ }
35
+ public String toString ()
36
+ {
37
+ return (name +" " +rollno +" " +marks );
38
+ }
39
+ }
40
+ class TreeSetTest2
41
+ {
42
+ public static void main (String s [])
43
+ {
44
+ TreeSet ts =new TreeSet ();
45
+ ts .add (new Student ("abc" ,103 ,86 ));
46
+ ts .add (new Student ("xyz" ,101 ,45 ));
47
+ ts .add (new Student ("abc" ,104 ,95 ));
48
+ ts .add (new Student ("hij" ,102 ,75 ));
49
+
50
+ Iterator itr =ts .iterator ();
51
+ while (itr .hasNext ())
52
+ {
53
+ System .out .println (itr .next ());
54
+ }
55
+ }
56
+ }
You can’t perform that action at this time.
0 commit comments