Duncan Jones
Duncan Jones

Reputation: 69359

Strange results with Path.startsWith()

Can anyone explain the following result?

Path p = Paths.get("/a/b");
System.out.println(p.startsWith(p.subpath(0, 1)));

Output:

false

I would expect it to be true, since the path begins with the first element of the path.

Upvotes: 1

Views: 230

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280064

subpath returns a relative path. An absolute path /a/b, does not start with a relative path a.

But a relative path a/b does start with a relative path a.

Upvotes: 5

Related Questions