拆分字符串但仅删除分隔符并保留空格 - java

Split a String but remove delimeters only and keep spaces - java

我有这样的字符串:

String str = "SOFTDRINK,SD03,Lemon juice,lemon juice,lemonjuice.img,30000.0";

// How can i get this expected string array:
String[] expected = ["SOFTDRINK","SD03","Lemon juice","lemonjuice","lemonjuice.img","30000.0"];

我使用 .split(",") 并迭代数组,在 space.

处的“柠檬汁”会出错

更新: 没有遇到 .split(",") 的错误。 我的字符串 str 没有如上所示返回,所以我遇到了与之相关的错误。

我认为你不应该在这里遇到任何错误

无论如何试试这个,你会得到你预期的输出

    String str = "SOFTDRINK,SD03,Lemon juice,lemon juice,lemonjuice.img,30000.0";
    String[] expected = str.split(",");
    System.out.println(Arrays.toString(expected));

即使没有成功,请添加更多代码