Enhanced for loop

什么是增强for循环?

The original for loop looks like this:

for(int i=0;i<10;i++)

Then let's take a look at the enhanced for loop:

for(object a:x)//It's not just what type of object array is stored, just fill in what type x is an array or a collection

It is implemented by the Interator iterator.
Note : When traversing, you cannot use the collection to add or delete elements. You can only operate through the iterator.

Because when the iterator is created, it will create a singly linked list. If the number of elements is manipulated through the collection, then the actual number has changed, but the singly linked list created by the iterator is still the same as the original, so when the sub-iterator traverses down, No actual value found

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324888285&siteId=291194637