This split behavior is inherited from Java, for better or worse ...
Scala does not override the definition from the String primitive.
Note that you can use the limit argument to change the behavior :
The limit parameter controls the number of uses of the template and, therefore, affects the length of the resulting array. If the limit n is greater than zero, the pattern will be applied no more than n - 1 times, the length of the array will be no more than n, and the last element of the array will contain all input data outside the last matched separator. If n is not positive, the pattern will be applied as many times as possible, and the array can be of any length. If n is zero, the pattern will be applied as many times as possible, the array can be of any length, and the final empty lines will be discarded.
i.e. you can set limit=-1 to get the behavior of (all?) other languages:
@ ",a,,b,,".split(",") res1: Array[String] = Array("", "a", "", "b") @ ",a,,b,,".split(",", -1) // limit=-1 res2: Array[String] = Array("", "a", "", "b", "", "")
It seems that the Java behavior looks rather confusing , but:
The behavior above can be observed at least from Java 5 to Java 8.
An attempt was made to change the behavior to return an empty array when splitting an empty string in JDK-6559590 . However, he was soon returned to JDK-8028321 when he causes regression in various places. This change never hits the original release of Java 8.
Note. The split method was not in Java from the very beginning (it is not in version 1.0.2 ), but actually there are less than 1.4 (for example, see JSR51 around 2002). I'm still investigating ...
It is not clear why Java chose this in the first place (my suspicion that it was originally an oversight / error in the "edge case"), but now it is irrevocably baked in this language, and therefore it remains .