Enhanced For Loop Java
Go to solution
Solved by wasab,
Arrays no because it doesn't implement iterable interface. To use enhance for loop, your collection of data must be able to return an iterator for the enhance loop to iterate. Also note that you can't modified the members in the list while iterating if you use arraylist or it will throw concurrent modification exception. Why not just iterate using an index instead?
Oh, any data structure that implement iterable can use enhance for loop.
Edit: never mind. Arrays can be used in enhance for. I never knew that.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now