Given that /data is a directory that exists and it is empty, what is the result of the following code?.
Path path = Paths.get("/data"); boolean myBoolean = Files.walk(path) .filter((p,a) -> a.isDirectory() && !path.equals(p)) // w1 .findFirst().isPresent(); // w2 System.out.println(myBoolean ? "No Sub-directory": "Has Sub-directory");
C.
The code does not compile since the stream output by Files.
walk()
is Stream<Path>, therefore we need a Predictate, not a BiPredicate, on line w1, and the answer is C.
If the Files.find()
method had been used instead, and the lambda had been passed as an argument to the method instead of on filter()
, the output would be B, Has Sub-directory, since the directory is given to be empty.
For fun, we reversed the expected output of the ternary operation to make sure that you understood the process.