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
About Question enthuware.ocpjp.v7.2.1414 :
Moderator: admin
-
- Posts: 23
- Joined: Sun Apr 14, 2013 10:37 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1414 :
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.
In case of foo, there is nothing after the second o. That is why you see a second blank.
-Paul.
-
- Posts: 23
- Joined: Sun Apr 14, 2013 10:37 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1414 :
Oh right I see.
Thanks.
Thanks.

-
- Posts: 15
- Joined: Thu Feb 05, 2015 3:50 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1414 :
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.
"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.
-
- Posts: 5
- Joined: Sun Jun 21, 2015 12:54 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1414 :
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?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1414 :
Because as per the JavaDoc API of this method, only the trailing empty strings are not included in the resulting array.
Who is online
Users browsing this forum: Bing [Bot] and 5 guests