Skip to content
CodeKruPro

Removing items while looping over a list

QuizMediumJava onlyAsked in: Accenture, Infosys, TCS

You must remove every expired item from an ArrayList. Which approaches are safe? Pick all that apply.

  • list.removeIf(item -> item.isExpired());
  • An Iterator loop that calls it.remove()
  • A for-each loop that calls list.remove(item)
  • A classic index loop from the last index down to 0 that calls list.remove(i)

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in