Page 1 of 1

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

Posted: Sun May 22, 2016 10:08 am
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?? :?

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

Posted: Sun May 22, 2016 8:37 pm
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.

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

Posted: Mon Oct 23, 2017 2:01 am
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.

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

Posted: Mon Oct 23, 2017 6:22 am
by admin
You may want to go through the JavaDoc description of the method to understand how it works.

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

Posted: Thu Nov 02, 2017 12:57 pm
by thodoris.bais
You're right, no trailing spaces after the delimiter's last match.