1Z0-819 · Question #80
Given: String originalPath = "data\\projects\\a-project\\..\\..\\another-project"; Path path = Paths.get(originalPath); System.out.print(path.normalize()); What is the result?
The correct answer is A. data\another-project. Path.normalize() resolves . (current dir) and .. (parent dir) segments, so data\\projects\\a-project\\..\\.. collapses by stepping up twice from a-project - first to projects, then to data - leaving data\\another-project, which is A. Why the distractors fail: B ignores the…
Question
Options
- Adata\another-project
- Bdata\projects\a-project\another-project
- Cdata\projects\a-project....\another-project
- Ddata\projects\a-project..\another-project
How the community answered
(58 responses)- A81% (47)
- B3% (2)
- C10% (6)
- D5% (3)
Explanation
Path.normalize() resolves . (current dir) and .. (parent dir) segments, so data\\projects\\a-project\\..\\.. collapses by stepping up twice from a-project - first to projects, then to data - leaving data\\another-project, which is A.
Why the distractors fail:
- B ignores the
..segments entirely, as ifnormalize()were never called. - C is the raw, un-normalized path - this would be the output of
path.toString(), notpath.normalize(). - D only removes one
..instead of both, which is a partial (incorrect) normalization.
Memory tip: Think of .. as a "delete the previous folder" instruction - count your .. segments and cancel them out one by one from right to left against the real path segments. Two .. after a-project erase a-project then projects, leaving only data.
Topics
Community Discussion
No community discussion yet for this question.