My blood is tested +ve for Java.
My blood is tested +ve for Java.
My blood is tested +ve for Java.
Chetan Parekh wrote:Got it!
John Laker wrote:
Can you explain that code a little bit ? What does the 1 do ?
luck, db
There are no new questions, but there may be new answers.
Darryl Burke wrote:
John Laker wrote:
Can you explain that code a little bit ? What does the 1 do ?
It's all there n the API for String#split(...)
The limit parameter controls the number ... If n is nonpositive then ...
The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n  1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is nonpositive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.
John Laker wrote:
Yes I read it, but had difficulty undestanding this quote there
The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n  1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is nonpositive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.
I'm not sure what pattern they are talking about and how it is applied to what.
My material for SCJP (2008), SCWCD (2010), SCBCD (2010). About me
T. Huy Nguyen wrote:
The 1st argument to split() is a regex pattern.
And if the 2nd parameter is negative (1), nothing is discarded. So the result is an array with 7 elements with the last 2 are empty stringS. These last 2 elements will be discarded if split("[]") or split ("[]", 0) are used
My material for SCJP (2008), SCWCD (2010), SCBCD (2010). About me
Yup, yup, yup. Tiny ad:
We need your help  Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanchserverfundraiser
