In Java, it's always confusing for an array to be able to use a foreach statement.
For objects that can be traversed with a foreach statement, there are only two cases, one of which is that traversing an object must implement the Iterable interface and implement the Ierator () method, which is the premise of the object using the foreach statement. Another case is a special object array. So how do you understand how to use foreach for arrays?
The first thing to note is that the object that implements the Java.lang.Iterable interface can be traversed with for-each, but it is not necessarily the interface that can be traversed with For-each , such as the special object of an array. However, there is little information on the Internet, but I can only say my own understanding.
I think it is possible for an array object to traverse an element with a foreach statement because the JVM converts the Foreach loop for the array to a circular reference to each of the arrays at the bottom. Similar to converting to a normal for statement at the bottom, we are guaranteed to iterate correctly when using the foreach statement.
Why arrays do not implement the Iterable interface, but can use a foreach statement to traverse