✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
What is the output of the following code:
import java.util.*;
class User {
String name;
User(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof User)) return false;
User user = (User) o;
return Objects.equals(name, user.name);
}
}
public class Test {
public static void main(String[] args) {
Set<User> users = new HashSet<>();
users.add(new User("Alice"));
users.add(new User("Alice"));
System.out.println(users.size());
}
}