Consider for(File file : files ) in the following code. I’ve never seen this syntax before. I understand from context and behavior that it’a a for loop based on the number of records…similar to (for x=0;x<length.foo;++x). Beyond that though, I’m not sure. Is this shorthand for a for loop that I’ve not learned yet? Is this a loop specifically for objects? More importantly… how do I describe it when I want to google information about that particular syntax?
CLARIFICATION: a second question, I’m also curious how this method of recursive file listing stores the list of filenames in file. Is this an array? a collection? or…? I’d like to know how I need to read the resulting file.
public static void main(String... aArgs) throws FileNotFoundException
{
File startingDirectory= new File("CGT");
List<File> files = WorkingFileListing2.getFileListingNoSort(startingDirectory);
for(File file : files )
{
System.out.println(file); //print filenames
}
}
It looks to me like the equivalent of a ‘foreach’ in C#. Searching Google for ‘Java foreach’ got me this:
Detail on Java For-Each loop