Java - How to split a string on plus signs?

前端 未结 2 1185
夕颜
夕颜 2020-12-03 20:48

I was trying to split an arithmetic expression (eg \"1+2+10+15\") on the plus signs. However, I didn\'t manage to write the appropriate regular expression. I thought this wo

2条回答
  •  旧时难觅i
    2020-12-03 21:07

    It does. However split(...) returns an array, it does not "transform" your String into a String[]. Try this:

    String expression = "1+2+10+1";
    String[] tokens = expression.split("\\+");
    

提交回复
热议问题