FileFilter is another functional interface that can be used to filter files and folders. For example, let's filter only folders:
File[] folders = path.toFile().listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
return file.isDirectory();
}
});
We can do the same in functional-style:
File[] folders = path.toFile().listFiles((File file)
-> file.isDirectory());
Let's make this more concise:
File[] folders = path.toFile().listFiles(f -> f.isDirectory());
Finally, we can do this via member reference:
File[] folders = path.toFile().listFiles(File::isDirectory);