Page 1 of 1
About Question enthuware.ocpjp.v7.2.1414 :
Posted: Thu May 02, 2013 3:46 pm
by RobynBackhouse
Puzzled..
When using the "o" as the Regex in the examples, why does it not give 2 empty matches for the "o"'s in boo, when it gives 2 matches for the ones in foo?
For a string of "boo:and:foo" I would have expected the answer to be either:
{ "b", "", "", ":and:f", "", "" }
or
{ "b", "", ":and:f", "" }
Why is there a difference between boo and foo in this case?
Thanks
Re: About Question enthuware.ocpjp.v7.2.1414 :
Posted: Thu May 02, 2013 4:11 pm
by admin
It doesn't give two blanks for boo because there is no blank after the second o. The second o is followed immediately by ":and:f". So there is only one blank between the two os.
In case of foo, there is nothing after the second o. That is why you see a second blank.
-Paul.
Re: About Question enthuware.ocpjp.v7.2.1414 :
Posted: Sat May 04, 2013 11:35 am
by RobynBackhouse
Oh right I see.
Thanks.

Re: About Question enthuware.ocpjp.v7.2.1414 :
Posted: Wed Nov 25, 2015 1:30 am
by Venceslas
Regarding the following expression:
"boo:and:foo".split("o",0)
and the result:
String result[] ={ "b", "", ":and:f" }
Why result[1] is "", I was under the comprehension it was discarded due to the fact "" result are discarded.
Thank you.
Re: About Question enthuware.ocpjp.v7.2.1414 :
Posted: Sun Jan 17, 2016 12:34 am
by abhimita
When I execute "1 dan 2 dave 3 dick".split("\\d") I get a space in the beginning and then the rest of the result. If the split() is executed with a 0(zero) limit then how come there is leading space? 'm a bit confused about the leading space. how is it occuring?
Re: About Question enthuware.ocpjp.v7.2.1414 :
Posted: Sun Jan 17, 2016 1:02 am
by admin
Because as per the JavaDoc API of this method, only the trailing empty strings are not included in the resulting array.