There are in JDK exist following split overloading signature
public String[] split(String regex, int limit)
Always I suppose that limit is the maximum number of tokens the string will be split.
for example:
first snippet:
System.out.println(Arrays.toString("Andrew Carnegie:35:USA".split(":")));
out:
[Andrew Carnegie, 35, USA]
second snippet:
System.out.println(Arrays.toString("Andrew Carnegie:35:USA".split(":",2)));
out
[Andrew Carnegie, 35:USA]
But I noticed 1 more effect
System.out.println(Arrays.toString("Andrew Carnegie:35:USA:".split(":")));
out:
[Andrew Carnegie, 35, USA]
and
System.out.println(Arrays.toString("Andrew Carnegie:35:USA:".split(":",-1)));
out:
[Andrew Carnegie, 35, USA, ]
Thus added an empty element if string ends by delimiter.
Where can I find specific information about this effect?