0
File lastModified = Arrays.stream(files)
    .filter(File::isDirectory)
    .max(Comparator.comparing(File::lastModified))
    .orElse(null)

Can the above code changed to be compatible for 1.7?

Simulant
  • 19,190
  • 8
  • 63
  • 98
Sandy Patel
  • 45
  • 1
  • 4
  • See also: https://stackoverflow.com/questions/16143684/can-java-8-code-be-compiled-to-run-on-java-7-jvm and https://github.com/luontola/retrolambda – JohannesB Mar 02 '19 at 16:51

2 Answers2

1

Provided files instanceof File[], it should be smth like that:

private static File getFileLastModified(File[] files) {
    File fileLastModified = null;
    long maxLastModified = Long.MIN_VALUE;
    for (File file : files) {
        if (file.isDirectory()) {
            final long lastModified = file.lastModified();
            if (lastModified > maxLastModified) {
                fileLastModified = file;
                maxLastModified = lastModified;
            }
        }
    }
    return fileLastModified;
}

In short, it tries to find the last modified file.

Dorian Gray
  • 2,913
  • 1
  • 9
  • 25
0

No, Stream API is available only from Java 8

upd: You can find a file with the most recent changes with a for loop. Check this post

Andrey Antipov
  • 370
  • 3
  • 9