forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
28 lines (20 loc) · 784 Bytes
/
Main.java
File metadata and controls
28 lines (20 loc) · 784 Bytes
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
package modern.challenge;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Player p1 = new Player(1, "Rafael Nadal");
Player p2 = new Player(1, "Rafael Nadal");
System.out.println(p1.equals(p2));
System.out.println(Objects.equals(p1, p2));
System.out.println("p1 hash code: " + p1.hashCode());
System.out.println("p2 hash code: " + p2.hashCode());
Set<Player> players = new HashSet<>();
players.add(p1);
players.add(p2);
System.out.println("Set size: " + players.size());
System.out.println("Set contains Rafael Nadal: "
+ players.contains(new Player(1, "Rafael Nadal")));
}
}