Java: How to remove elements from a list while iterating over/adding to it

后端 未结 9 1915
谎友^
谎友^ 2020-12-10 11:38

This question is a more special case of the problem described (and solved) in this question.

I have two methods, stopAndRemove(ServerObject server) and a close() met

9条回答
  •  感情败类
    2020-12-10 12:13

    Split off a method stop() from stopAndRemove(). Then write the loop with an explicit iterator, do the stop and then iterator.remove().

    "and" in a method name is a code smell.

提交回复
热议问题