oluies oluies - 2 months ago 5x
Scala Question

Why does "split" on an empty string return a non-empty array?

Split on an empty string returns an array of size 1 :

scala> "".split(',').length
res15: Int = 1

scala> "".split(',')
res17: Array[String] = Array()

Please explain :) (Since I love the way that Guava splitters are configurable and super nice!)


For the same reason that

",test" split ','


",test," split ','

will return an array of size 2. Everything before the first match is returned as the first element.