Challenge exercise The for-each loop does not use an explicit integer variable to access successive elements of the list. Thus, if we want to include the index of each file name in the listing, then we would have to declare our own local integer variable (position, say) so that we can write in the body of the loop something like:
System.out.println(position + ": " + filename);
See if you can complete a version of listAllFiles to do this. Hint: You will need a local variable declaration of position in the method, as well as a statement to update its value by one inside the for-each loop.
One of the things this exercise illustrates is that the for-each loop is not really intended to be used with a separate index variable.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.