java - Foreach loop can cause thread concurrency? -


i've heard shouldn't use foreach loop can avoid because can cause thread concurrency, mean thread concurrency, , true ?

so when should use for-each loop?

any time can. beautifies code. unfortunately, cannot use everywhere. consider, example, the expurgate method. program needs access iterator in order remove current element. the for-each loop hides iterator, cannot call remove. therefore, for-each loop not usable filtering. it not usable loops need replace elements in list or array traverse it. finally, it not usable loops must iterate on multiple collections in parallel.

these shortcomings known designers, made conscious decision go clean, simple construct cover great majority of cases.

emphasis mine.

unless clear mean exactly, indicate you're wrong.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -