RESOLVED.
Hi,
So basically in short p1 must be the same as p2 in order to return true.
The name is quite confusing as it says startsWith, one would expect to check only the beginning
Forget about it checks only N elements belonging to the other path (the one passed as argument)
Thanks.
The_Nick.
About Question enthuware.ocpjp.v7.2.1214 :
Moderator: admin
-
- Posts: 132
- Joined: Thu May 16, 2013 9:23 am
- Contact:
-
- Posts: 3
- Joined: Sat Jan 04, 2025 6:45 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1214 :
Output under Linux:
java --version
openjdk 21.0.5 2024-10-15
OpenJDK Runtime Environment (Red_Hat-21.0.5.0.11-1) (build 21.0.5+11)
OpenJDK 64-Bit Server VM (Red_Hat-21.0.5.0.11-1) (build 21.0.5+11, mixed mode, sharing)
improved code:
Code: Select all
\temp\records/clients.dat false
openjdk 21.0.5 2024-10-15
OpenJDK Runtime Environment (Red_Hat-21.0.5.0.11-1) (build 21.0.5+11)
OpenJDK 64-Bit Server VM (Red_Hat-21.0.5.0.11-1) (build 21.0.5+11, mixed mode, sharing)
improved code:
Code: Select all
public static void writeData() {
// var p1 = Paths.get("\\temp\\records");
// var p2 = p1.resolve("clients.dat");
var p1 = Paths.get("temp", "records");
var p2 = p1.resolve("clients.dat");
System.out.println(p2 + " " + isValid(p2));
}
-
- Posts: 11
- Joined: Fri Feb 07, 2025 5:36 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1214 :
Hello,
In the same test question 14's solution says "4. paths do not start or end with \." resolve method returns a Path object right, so why is this one returning a path that starts with "\". thanks.
In the same test question 14's solution says "4. paths do not start or end with \." resolve method returns a Path object right, so why is this one returning a path that starts with "\". thanks.
-
- Site Admin
- Posts: 10409
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1214 :
If you mean qid 2.1579 , the first line of the explanation clearly says - "Remember the following points about Path.subpath(int beginIndex, int endIndex)". So those 4 points are about the Path.subpath method. The Path object that this method returns does not start with \.
Who is online
Users browsing this forum: No registered users and 32 guests