Java circular traversal method for deleting elements in list and set sets (recommended)

Today, when I was working on a project, I needed to delete some elements in the list and set. At that time, I used the method of traversing while deleting, but the following exception was reported:

ConcurrentModificationException

In order not to forget it later, use a rotten pen to record it as follows:

The writing method of error code, that is, the writing method of reporting the above exception:

Note: if you use the above writing method, the concurrencemodificationexception above will be reported. The reason is that the collection cannot be deleted while traversing.

The correct wording is as follows:

1. Traverse and delete list

2. Traverse delete set

The above circular traversal method to delete elements in list and set sets in Java (recommended) is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>