I want to implement a method like this:
public Iterator<File> getFiles(String root) {
// return an Iterator looping through all files in root and all files in sub-directories of roots (recursively)
}
In C #, this can be easily implemented using a keyword yield return. In Java, I suspect that I need to write a lot of complex code to do this. Is there a good solution to this problem?
Edit: I want the returned Iterator to be "lazy", i.e. returned a new file only when called next(). (This suggestion C # yield returnoffers.)
source
share