Created
March 19, 2015 23:38
-
-
Save bcalmac/08a5d5219afa9a62811a to your computer and use it in GitHub Desktop.
Java string splitting quirks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Splitting an empty string returns an array with an empty string | |
assert "".split(";") == [""] | |
// Splitting a string consisting of just the delimiter returns an empty array | |
assert ";".split(";") == [] | |
// Trailing delimiters are ignored | |
assert "1;;2;;".split(";") == ["1", "", "2"] | |
// ... but the behavior becomes consistent with a -1 extra argument | |
assert ";".split(";", -1) == ["", ""] | |
assert "1;;2;;".split(";", -1) == ["1", "", "2", "", ""] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment