Assume /data exists as a regular directory containing multiple files, symbolic links, and subdirectories.
What is true about the following code? (Choose all that apply.).
Path path = Paths.get("/data"); Files.find(path, 0, (p,a) -> a.isSymbolicLink()).map(p -> p.toString()) // y1 .collect(Collectors.toList()) // y2 .stream() // y3 .filter(x -> x.toString().endsWith(".txt")) // y4 .forEach(System.out::println);
B.
The code compiles and runs without issue, so C, D, E, F, and G are incorrect.
Note that the sample code creates a stream, collects it as a list, and then converts it back to a stream before outputting the filenames.
The key here is that the depth parameter specified as the second argument to find()
is 0, meaning the only record that will be searched is the top level directory.
Since we know that the top directory is regular and not a symbolic link, no other paths will be visited and nothing will be printed.
B is the correct answer and A is incorrect.