Java - How to split a string on plus signs?

前端 未结 2 1168
夕颜
夕颜 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条回答
  • 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("\\+");
    
    0 讨论(0)
  • 2020-12-03 21:25

    this way

    expression.split("[+]");
    
    0 讨论(0)
提交回复
热议问题