How to split string with trailing empty strings in result?

后端 未结 2 948
一整个雨季
一整个雨季 2020-12-10 10:58

I am a bit confused about Scala string split behaviour as it does not work consistently and some list elements are missing. For example, if I have a CSV string with 4 column

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 11:08

    I believe that trailing empty spaces are not included in a return value.

    JavaDoc for split(String regex) says: "This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array."

    So in your case split(String regex, int limit) should be used in order to get trailing empty string in a return value.

提交回复
热议问题