0

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

14
  • 3
    Things like removeAll will rely on the equals and hashcode support of the object to determine equality. You could implement this interfaces or you could simply run through both arrays and manually match elements Commented May 19, 2020 at 22:57
  • 1
    You need to define equals and hashCode otherwise identical times will point to different references, and equals will fail. Commented May 19, 2020 at 22:57
  • 1
    There is the method ArrayList#removeAll(Collection). But you have to override equals for ScheduleTime so identical elements are identified. Commented May 19, 2020 at 22:57
  • 1
    can somebody upvote my question?? i think its a nice question Commented May 19, 2020 at 23:12
  • 1
    @aspertimetechnologies Generally we don't post comments with any recommendations to upvote/downvote or close, aspertime. People should make up their own minds about it. Commented May 19, 2020 at 23:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.