File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ //version 11.1
2
+
3
+ import java .util .*;
4
+
5
+ class Student
6
+ {
7
+ int rollno ,marks ;
8
+ char grade ;
9
+ String name ;
10
+ Student (int rollno ,int marks ,String name )
11
+ {
12
+ this .rollno =rollno ;
13
+ this .marks =marks ;
14
+ this .name =name ;
15
+ }
16
+ public String toString ()
17
+ {
18
+ return (rollno +" " +name +" " +marks );
19
+ }
20
+ public int hashCode ()
21
+ {
22
+ return (rollno );
23
+ }
24
+ public boolean equals (Object ob )
25
+ {
26
+ Student st =(Student )ob ;
27
+ return (rollno == st .rollno && marks == st .marks );
28
+ }
29
+ }
30
+ class HashSetTest2
31
+ {
32
+ public static void main (String s [])
33
+ {
34
+ HashSet hs =new HashSet ();
35
+ hs .add (new Student (101 ,85 ,"abc" ));
36
+ hs .add (new Student (102 ,75 ,"xyz" ));
37
+ hs .add (new Student (103 ,65 ,"pqr" ));
38
+ hs .add (new Student (101 ,85 ,"hij" ));
39
+
40
+ Iterator itr =hs .iterator ();
41
+ while (itr .hasNext ())
42
+ {
43
+ System .out .println (itr .next ());
44
+ }
45
+ }
46
+ }
47
+
You can’t perform that action at this time.
0 commit comments