Splitting String in Java with empty elements

后端 未结 3 1192
后悔当初
后悔当初 2021-01-27 12:16

I\'m reading from a .csv File line by line. One line could look for example as following: String str = \"10,1,,,,\".

Now I would like to split according to

3条回答
  •  鱼传尺愫
    2021-01-27 12:40

    Pass -1 (or any negative number, actually) as a second parameter to split:

    System.out.println("0,,,,,".split(",", -1).length); // Prints 6.
    

提交回复
热议问题