-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashingBasic.java
More file actions
79 lines (63 loc) · 1.77 KB
/
Copy pathHashingBasic.java
File metadata and controls
79 lines (63 loc) · 1.77 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package hashingAndHashmap;
import java.util.HashSet;
import java.util.Set;
public class HashingBasic {
public static void main(String[] args) {
// //HashMap
// HashMap<String,String> map = new HashMap<>();
// map.put("One","I");
// map.put("Two","II");
// map.put("Three","III");
//
// System.out.println(map);
//HashSet
// HashSet<Integer> set = new HashSet<>();
// set.add(34);
// set.add(3);
// set.add(4);
// set.add(3);
// System.out.println(set);
// Set<Student> rollCall = new HashSet<>();
// Student s1 = new Student(1, "Pradip");
// Student s2 = new Student(2, "Aman");
// Student s3 = new Student(3, "Pradip");
//
// rollCall.add(s1);
// rollCall.add(s2);
// rollCall.add(s3);
//
// System.out.println(rollCall);
// Student s4 = new Student(1, "Pradip");
// rollCall.add(s4);
// System.out.println(rollCall);
Set<Student> rollCall = new HashSet<>();
Student s1 = new Student(1, "pradip");
Student s2 = new Student(1, "Aman");
System.out.println(s1.hashCode());
System.out.println(s1.hashCode());
System.out.println(s1.equals(s2));
}
}
class Student {
int rollNo;
String name;
public Student(int rollNo, String name) {
this.rollNo = rollNo;
this.name = name;
}
public String toString() {
return "(" + rollNo + " , " + name + ")";
}
// @Override
// public int hashCode(){
// return rollNo;
// }
@Override
public boolean equals(Object obj) {
Student that = (Student) obj;
if (this.rollNo == that.rollNo) {
return true;
}
return false;
}
}