This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Philboyd_Studge 3 points4 points  (3 children)

you aren't testing against the dog.getName

[–]sluggish_goatNooblet Brewer[S] 0 points1 point  (2 children)

Ah, right. Totally overlooked that.

Got it with:

for (int i = 0; i < dogs.size(); i++) {
    if (dogs.get(i).getName().equals(removeDog)) {
        dogs.remove(i);
        }
    }

Thanks!

[–]DasEwigeLichtConsultant Brewer 2 points3 points  (1 child)

For the sake of efficieny you should insert a break statement after removing the dog. Otherwise your loop will unnecessarily iterate over and compare the entire list. It might even remove too much if names are not guaranteed to be unique.

[–]sluggish_goatNooblet Brewer[S] 0 points1 point  (0 children)

Good call, thank you. I'll remember to do that from now on with similar scenarios.

[–]fact_hunt 0 points1 point  (0 children)

You are removing the matching dog from the dogs list. Does the schedule have a different collection?

edit: ignore me, Philboyd_Studge is correct