Java OCA OCP Practice Question 2271

Question

Consider the following code segment:.

try(Stream<Path> entries = Files.find(Paths.get("."), 4, predicate)) {
     entries.forEach(System.out::println);
}

Which one of the following is a valid definition of the variable predicate that can be used in this code segment?.

A.  BiPredicate<Path, BasicFileAttributes> predicate = (path, attrs)
               -> true;

B.   Predicate<Path> predicate = (path) -> true

C.   Predicate<BasicFileAttributes> predicate = (attrs) -> attrs.
               isRegularFile();

D.   Predicate predicate = FileVisitOption.FOLLOW_LINKS;


A.

Note

the find() method takes the path to start searching from, the maximum depth to search, a BiPredicate, and an optional FileVisitOption as arguments:.

Option a provides a definition of BiPredicate and hence it is the correct answer.

Using the other options will result in a compiler error.




PreviousNext

Related