About Question enthuware.ocpjp.v7.2.1413 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Nisim123
Posts: 42
Joined: Mon Jan 20, 2014 2:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by Nisim123 »

No... you are the one who should be thanked! :-)
and still in our case, i mean in this question, it does not start with a positive- width match,
nor there is a reason for an empty string to be returned, so why does it return an empty string from that position in the string that contains two of the delimiter in a row?? :?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by admin »

As per my interpretation of the documentation, there is a match on the first character and so it will return an empty string as the first token.
Regarding the code given in the question, it also behaves exactly as given in the JavaDoc. You have two semicolons together and so it returns and empty token. Now, why it returns an empty token is something that only the API designers can answer. One can certainly design a split method that does behave like this but the JDK designers chose not to. Can't really do much about it :)

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

thodoris.bais
Posts: 25
Joined: Sat Jun 03, 2017 4:56 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by thodoris.bais »

I am still not fully sure if I understand why the correct answer is
A String array containing 3 elements
, instead of
A String array containing 4 elements
, despite the fact of this mention in the explanation:
The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by admin »

You may want to go through the JavaDoc description of the method to understand how it works.
If you like our products and services, please help us by posting your review here.

thodoris.bais
Posts: 25
Joined: Sat Jun 03, 2017 4:56 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by thodoris.bais »

You're right, no trailing spaces after the delimiter's last match.

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests