Java String split removed empty values

前端 未结 5 1256
无人及你
无人及你 2020-11-21 18:41

I am trying to split the Value using a separator. But I am finding the surprising results

String data = \"5|6|7||8|9||\";
String[] split = data.split(\"\\\\|         


        
5条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 19:24

    From String.split() API Doc:

    Splits this string around matches of the given regular expression. 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.

    Overloaded String.split(regex, int) is more appropriate for your case.

提交回复
热议问题