java - Behaviour of String.split() when input is empty -


as title explains query

can please explain behavior of following 2 outputs.

"".split(",").length 

gives output

1 

where as

",".split(",").length 

gives output

0 

in first case, original string returned, because separator not found.

from api docs:

if expression not match part of input resulting array has 1 element, namely string.


Popular posts from this blog

Php - Delimiter must not be alphanumeric or backslash -

c# - How to change the "Applies To" field under folder auditing options programatically (.NET) -

c++ - Ambiguity when using boost::assign::list_of to construct a std::vector -