Better practice to re-instantiate a List or invoke clear()

前端 未结 4 384
执念已碎
执念已碎 2020-12-03 00:53

Using Java (1.6) is it better to call the clear() method on a List or just re-instantiate the reference?

I have an ArrayList that is filled with an unknown number of

4条回答
  •  既然无缘
    2020-12-03 01:22

    The way you are using it looks very much like how a Queue is used. When you work of the items on the queue they are removed when you treat them.

    Using one of the Queue classes might make the code more elegant.

    There are also variants which handle concurrent updates in a predictable way.

提交回复
热议问题