Implement the Person class to have a HashMap filled with unique pairs where the key is of Person type.
hashCode() and equals() in Collections
Unique pairs in HashMap
Report a typo
Sample Input 1:
James Gosling
James GoslingSample Output 1:
1Write a program in Java 17
import java.util.Scanner;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Map<Person, Integer> map = new HashMap();
map.put(new Person(scanner.nextLine()), 1995);
map.put(new Person(scanner.nextLine()), 1995);
System.out.println(/* Print the map size here */);
}
}
class Person {
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.