A
Alan
I am trying to iterate through a List<File>, but the compiler
does not like when I try to assign the next item to a File type. It
says that file and it.next() are incompatible types, but each item of
filelist is supposed to be of type File. The error occurs at the
line:
File file = it.next();
The code may be found below. Note that the method listAllFiles
returns List<File>.
What am I doing wrong? Thanks, Alan
List<File> filelist = listAllFiles(directory, "*.java");
for (Iterator it = filelist.iterator(); it.hasNext()
{
File file = it.next();
System.out.println(file.getName());
}
does not like when I try to assign the next item to a File type. It
says that file and it.next() are incompatible types, but each item of
filelist is supposed to be of type File. The error occurs at the
line:
File file = it.next();
The code may be found below. Note that the method listAllFiles
returns List<File>.
What am I doing wrong? Thanks, Alan
List<File> filelist = listAllFiles(directory, "*.java");
for (Iterator it = filelist.iterator(); it.hasNext()
{
File file = it.next();
System.out.println(file.getName());
}