Implement the Person class to allow HashSet to have duplicate elements.
hashCode() and equals() in Collections
Duplicate elements in HashSet
Report a typo
Sample Input 1:
James Gosling
James GoslingSample Output 1:
2Write 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);
Set<Person> set = new HashSet();
set.add(new Person(scanner.nextLine()));
set.add(new Person(scanner.nextLine()));
System.out.println(/* Print the set 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.