Java Reference
In-Depth Information
Equivalent to split(regex,0) (see below).
public String[] split(String regex, int limit)
Returns an array of strings resulting from splitting up this
string according to the regular expression. Each match of the
regular expression will cause a split in the string, with the
matched part of the string removed. The limit affects the
number of times the regular expression will be applied to the
string to create the array. Any positive number n limits the
number of applications to n 1, with the remainder of the string
returned as the last element of the array (so the array will
be no larger than n ). Any negative limit means that there is
no limit to the number of applications and the array can have
any length. A limit of zero behaves like a negative limit, but
trailing empty strings will be discarded. Invoked on str , this
is equivalent to Pattern.compile(regex).split(str, limit) .
This is easier to understand with an example. The following
table shows the array elements returned from split("--",n)
invoked on the string "w--x--y--" for n equal to 1, 0, 1, 2, 3,
and 4:
Limit: -1 0 1 2
3 4
Results
[0]: w w w--x--y-- w
w w
[1]: x x x--y--
x x
[2]: y y
y-- y
[3]:
"" ""
With a negative or zero limit we remove all occurrences of
"--" , with the difference between the two being the trailing
empty string in the negative case. With a limit of one we don't
 
Search WWH ::




Custom Search