Here is the scenario. I want to avoid duplicates only if 2 among the 3 fields are same value. Id will be different but if name and address both are same then that should be avoided.
I tried the following code where I add some name, id and address
HashSet<Employee> mySet = new HashSet<Employee>();
mySet.add(new Employee (1,"a","xxx"));
mySet.add(new Employee(2,"a", "yyy"));
for(Employee emp : mySet) {
System.out.println(emp.getId() + " " + emp.getName()+" "+emp.getAddress());
}
I have one Employee class with setters and getters and constructor of my choice.
I wanna avoid printing if name and address (both) are gonna be repeated.
1 A xxx
2 A xxx
The above scenario should be avoided
Can you please help me with logic ?