I just recently found out that Java's String split method works in (at least for me) unexpected ways:
"hello".split(",").length // -> 1
",".split(",").length // -> 0
",,".split(",").length // -> 0
" ,,".split(",").length // -> 1
"".split(",").length // -> 1
Is it just me that thinks this is weird?
- Did they forget about empty strings?
- Isn't this a possible source of bugs -- I'm thinking CSV, etc.
- Isn't "split" breaking SRP, meaning, it doesn't just split, it also checks if the result is non-empty
Is there some possible explanation why they decided to do this? Mostly out of curiousity.