Java - How to split a string on plus signs?

Viewed 49602

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 would work:

expression.split("\\+");

but it doesn't. Do you know the correct solution?

2 Answers

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("\\+");
Related