How we can delete duplicate entries from StudentList object. Here we can identify student is duplicate or not if more according to entry sequence.
class Student
{
String name;
long phone;
String address;
boolean isActive;
Student(String name, long phone, String address, boolean isActive)
{
this.name = name;
this.phone = phone;
this.address = address;
this.isActive = isActive;
}
}
this is execution class.
class CollegeMgmt
{
public static void main(String s[])
{
ArrayList<Student> studentList = new ArrayList<Student>();
Student s1 = new Student("devid", 9898989898L, "Stainford d23", true);
studentList.add(s1);
Student s2 = new Student("sames", 9895555598L, "Stainford d23", true);
studentList.add(s2);
Student s3 = new Student("devid", 9898989898L, "Stainford d23", false);
studentList.add(s3);
Student s4 = new Student("devid", 9898989898L, "Stainford d23", false);
studentList.add(s4);
Student s5 = new Student("devid", 9898989898L, "Stainford d23", true);
studentList.add(s5);
}
}
I want to know which approach will be best to delete all duplicate entries from studentList. duplicate is here if two or more entry are same as
Student s3 = new Student("devid", 9898989898L, "Stainford d23", false);
studentList.add(s1);
Student s4 = new Student("devid", 9898989898L, "Stainford d23", false);
studentList.add(s1);
this is on the behalf of isActive bit, if in our list continues same bit we are setting then that object is need to delete. there s4 object should be remove no other object should be remove.