i have a class called ScheduleTime.
public class ScheduleTime {
String date;
Integer hours;
Integer minutes;
}
now i have two ArrayList one is called timeSlots and another is called bookingArray both are of type ScheduleTime .. with some items in them.
Now i want to delete all the elements in timeSlots which are the same as elements of bookingArray
I have tried this
timeSlots.removeAll(bookingArray);
But still timeSlots remain the same i don't know why
removeAllwill rely on theequalsandhashcodesupport of the object to determine equality. You could implement this interfaces or you could simply run through both arrays and manually match elementsequalsandhashCodeotherwise identical times will point to different references, andequalswill fail.ArrayList#removeAll(Collection). But you have to overrideequalsforScheduleTimeso identical elements are identified.