About Question enthuware.ocpjp.v7.2.1414 :

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

Moderator: admin

Post Reply
RobynBackhouse
Posts: 23
Joined: Sun Apr 14, 2013 10:37 am
Contact:

About Question enthuware.ocpjp.v7.2.1414 :

Post 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

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

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

Post 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.

RobynBackhouse
Posts: 23
Joined: Sun Apr 14, 2013 10:37 am
Contact:

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

Post by RobynBackhouse »

Oh right I see.
Thanks. :D

Venceslas
Posts: 15
Joined: Thu Feb 05, 2015 3:50 pm
Contact:

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

Post 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.

abhimita
Posts: 5
Joined: Sun Jun 21, 2015 12:54 am
Contact:

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

Post 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?

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

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

Post by admin »

Because as per the JavaDoc API of this method, only the trailing empty strings are not included in the resulting array.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests