Duplicate elements in HashSet

Report a typo

Implement the Person class to allow HashSet to have duplicate elements.

Sample Input 1:

James Gosling
James Gosling

Sample Output 1:

2
Write 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 {
}
___

Create a free account to access the full topic