Java Split() Method

public String[] split(String regex, int limit) {}

+limit > 0: return exactly the number of substrings indicated
ex: limit = 3: return exactly an array with first 3 substrings even though the father string can be splitted into more than 3 substrings
[1;2;3;4;5;] -> Only 1 2 3 are return

+limit = 0: return exactly the number of substrings are splitted EXCEPT the trailing white space at the end.
ex:
[1;2;3;4;5; ] -> 1 2 3 4 5 are returned, [] is not returned

+limit < 0: return all the substrings found, INCLUDING trailing whitespace
ex: limit = -1
[1;2;3;4;5; ] -> 1 2 3 4 5 are returned, AND [] is returned ALSO
[1;2;3;4;5;] -> 1 2 3 4 5 are returned ONLY, [] is NOT returned (because no whitespace here)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.