Given the code fragment:
What is the result?
Given the code fragment:
What is the result?
In the given Java code, the first statement creates a Path instance for the path '/software/././sys/readme.txt'. Using the 'normalize()' method on this path removes redundant elements like '.' and returns '/software/sys/readme.txt'. The name count for the original path ('path1') is 5 since '/software/././sys/readme.txt' consists of 5 elements. The name count for the normalized path ('path2') is 3 because '/software/sys/readme.txt' has 3 elements. When 'path2.relativize(path1)' is called, it computes the relative path from the normalized path back to the original path. The relative path between '/software/sys/readme.txt' and '/software/././sys/readme.txt' includes all the redundant path names in the original path, resulting in a total of 6 elements. Hence, the answer is '5 : 3 : 6'.
Answer is A tested
By me answer is: 5 3 1
Answer is A.I tested it with JDK8
Path path1 = Paths.get("/software/././sys/readme.txt"); Path path2 = path1.normalize(); Path path3 = path2.relativize(path1); System.out.print(path1.getNameCount()); System.out.print(" : " + path2.getNameCount()); System.out.print(" : " + path3.getNameCount()); ---------------------------------------------------------------------------------- 5 : 3 : 1 Process finished with exit code 0
A is the correct answer
Answer is A, I tested it with JDK8.
Using JDK8 I got 5:3:6. Answer is definitely A
p1.relativize(p1).getNameCount(); // 1 p2.relativize(p1).getNameCount(); // 6