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
While I agree that the accepted answer is usually the best solution and definitely easier to use, I noticed no one displayed the proper usage of the iterator. So here is a quick example:
Iterator it = arrayList.iterator(); while(it.hasNext()) { Object obj = it.next(); //Do something with obj }