cmbhatt
Originally posted by anil kumar:
hi
chandra
>< //beginning blank string
> < //space after that
what is the difference between those two comments?
please exaplain that
Thanks
Anil Kumar
cmbhatt
Matt
Inquisition: open-source mock exam simulator for SCJP and SCWCD
cmbhatt
Matt says,
In the case of " apples".split("\\w*"), the regular expression matches three times ("" at the start of the string, "apples", and "" at the end of the string
cmbhatt
cmbhatt
Matt
Inquisition: open-source mock exam simulator for SCJP and SCWCD
Originally posted by anil kumar:
Hi
This is the only thing i could not understood since morning
3) String str = "apples ";
String s[] = str.split("\\w*");
for (String i:s)
System.out.println("Token" + i + "Token");
Output is :
TokenToken
TokenToken
Token Token ////line1
Matt
Inquisition: open-source mock exam simulator for SCJP and SCWCD
Originally posted by M Krishnan:
Matt
Inquisition: open-source mock exam simulator for SCJP and SCWCD
cmbhatt
cmbhatt
cmbhatt
cmbhatt
String [] tokens = "".split("x*");
for (String s : tokens) System.out.print(">" + s + "<");
----------------------------------------------------------
gives output:
><
I thought trailing empty strings are discarded, so the output should be nothing... ?
If this pattern does not match any subsequence of the input then the resulting array has just one element, namely the input sequence in string form.
Matt
Inquisition: open-source mock exam simulator for SCJP and SCWCD
Originally posted by Henry Wong:
Oops, I was wrong. This exception condition is documented in the JavaDoc...
It looks like if there are no matches for the split delimiter, then the limit part of split (and any side effects) is not even applied.
Henry
Matt
Inquisition: open-source mock exam simulator for SCJP and SCWCD
Originally posted by Matt Russell:
Sure...but in the case of "".split("x*"), there is one match.
Originally posted by Henry Wong:
Actually, no. I was referring to the matching of the delimiter, not the results. There are no x's to match.
Henry
Matt
Inquisition: open-source mock exam simulator for SCJP and SCWCD
It's quite possible I'm being dense and missing something, though ;-)
Originally posted by Matt Russell:
I was referring to the matching of the delimiter too -- * matches 0 or more: so x* matches even though there are no x's to match. It's quite possible I'm being dense and missing something, though ;-)
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|