Thread safety when iterating through an ArrayList using foreach

后端 未结 4 1718
既然无缘
既然无缘 2021-01-02 09:25

I\'ve got an ArrayList which is being instantiated and populated on the background thread (I use it to store the Cursor data). At the same time it

4条回答
  •  旧巷少年郎
    2021-01-02 10:16

    Use Collections.synchronizedList(new ArrayList());

    Ex:

    Collections.synchronizedList(mList);
    

提交回复
热议问题