Right now, I have a program containing a piece of code that looks like this:
while (arrayList.iterator().hasNext()) {
//value is equal to a String value
iterating using iterator is not fail-safe for example if you add element to the collection after iterator's creation then it will throw concurrentmodificaionexception. Also it's not thread safe, you have to make it thread safe externally.
So it's better to use for-each structure of for loop. It's atleast fail-safe.