代码如下,其他代码和老师的相同
public void testRemove(Student student)
{
String string = "数据结构";
for (Course cr : student.courses) {
if(cr.name.equals(string))
{
student.courses.remove(cr));
}
}
我使用这个方法会报错,
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:922)
at java.util.HashMap$KeyIterator.next(HashMap.java:956)
at study.day1216.SetTest.testRemove(SetTest.java:60)
at study.day1216.SetTest.main(SetTest.java:44)
sxian_wang
相关分类