Splitting String in Java with empty elements

后端 未结 3 1187
后悔当初
后悔当初 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:48

    split only drops trailing delimeters by default. You can turn this off with

    String str = "9,,,1,,";
    String[] parts = str.split(",", -1);
    System.out.println(Arrays.toString(parts));
    

    prints

    [9, , , 1, , ]
    

提交回复
热议问题