public class UserDefinedObject {
public static void main(String[] args) {
Contact con1 = new Contact("Paras", "Puru", 901965);
Contact con2 = new Contact("Paras", "Puru", 901965);
Contact con3 = new Contact("Ajit", "Kumar", 901965);
Contact con4 = new Contact("Anil", "Aryan", 901965);
Contact con5 = new Contact("Prem", "Mahto", 901965);
Contact con6 = new Contact("Anil", "Aryan", 901965);
Contact con7 = new Contact("Paras", "Puru", 901965);
Set<Contact> set = new HashSet<Contact>();
set.add(con1);
set.add(con2);
set.add(con3);
set.add(con4);
set.add(con5);
set.add(con6);
set.add(con7);
/*for (Contact contact : set) {
System.out.println(contact);
}*/
set.forEach(s -> System.out.println(s));
}
}
class Contact {
private String firstName;
private String lastName;
private int phone;
public Contact(String firstName, String lastName, int phone) {
this.firstName = firstName;
this.lastName = lastName;
this.phone = phone;
}
@Override
public String toString() {
return "Contact [firstName=" + firstName + ", lastName=" + lastName + ", phone=" + phone + "]";
}
}