How can i remove objects having the same state.
class Student{
private int age;
private String name;
Student(int age, String name){
this.age=age;
this.name=name;
} }
public class SetTest {
public static void main(String[] args) {
Student s1= new Student(15,"abc");
Student s2= new Student(15,"abc");
Student s3= new Student(16,"adfc");
Student s4= new Student(14,"ayuc");
Set<Student> ss= new HashSet<Student>();
ss.add(s1); ss.add(s2); ss.add(s3); ss.add(s4);}}
here s1 and s2 are having equal state and as i am using Set and I want to keep only one instance. What should i do to take only object with non-equal instance.