Hi there, quick question about split method for St...
# announcements
j
Hi there, quick question about split method for String if I have val v = "" then I do v.split(".") I expect the method to return an empty List, but it actually returns a list with one element, and that element is my original string "" I can confirm that by looking at the code:
Copy code
private fun CharSequence.split(delimiter: String, ignoreCase: Boolean, limit: Int): List<String> {
    require(limit >= 0, { "Limit must be non-negative, but was $limit." })

    var currentOffset = 0
    var nextIndex = indexOf(delimiter, currentOffset, ignoreCase)
    if (nextIndex == -1 || limit == 1) {
        return listOf(this.toString())  -- HERE IT IS
    }
Is this a behavior i should expect?
v
Of course
j
Well, looking it again I think it is...
v
If you split "asdf" by ":" there is exactly one chunk which is identical to the input string
empty string is no different
j
right, exactly
thats what i thought after looking at the code again
thanks for the reply
v
yw