In fact, the reason for reporting an error is to throw an exception, which violates the fail fast protection mechanism
At this point, we replace the iterator to implement the loop
List<String> list=new ArrayList<>();
list.add("1");
list.add("2");
Iterator<String> iterator=list.iterator();
while(iterator.hasNext()){
String item=iterator.next();
if(Conditions for deleting elements){
iterator.remove();
}
}
Exception Writing
for(String item:list){
if(Conditions){
list.remove(item);
}
}
Read More:
- Java — for loop printing graphics (loop structure)
- How to Solve java server error (java application Run Normally)
- How to Remove “Devtools failed to parse sourcemap” Warning
- How to Solve Error:java.io.InvalidClassException
- How to Solve Java Runtime (class file version 53.0)ERROR
- [Solved] Springboot uses redis to add LocaldateTime Java 8 error
- How to Solve Flynk Task Java verifyerror 209 error
- How to Solve Java Error \ufeff
- How to Solve Flick operate Error: not serialized
- How to Solve Hbase JAVA import Package Error
- How to Solve ERROR: Java 1.7 or later is required to run Apache Drill
- How to Solve IntelliJ IDEA Error: Cannot determine path to ‘tools.jar‘ library for 17 (C:\Program Files\Java\jd…
- How to Solve JAVA Error: error: A JNI error has occureed
- JAVA 8: How to Convert List to Map
- JAVA: How to Read JSON Format Data (Web Game Development)
- [Solved] IDEA Add maven Project Error: Error:(3,21)java: Package javax.servletdoes not exist
- How to Solve mybatis-plus Paging Plug-in PaginationInnerInterceptor error
- How to convert a Java string into a number (stringtonumber)
- Mac: How to Solve ERROR launching ‘JD-GUI‘
- AlmaLinux 9.1: How to Install java11