String s = " x + y ";
String[] sArr = s.split("\\s*-|+|*|/\\s*");
I have a String such as: " x + y " I want to get an array with elements: x, +, y (no whitespaces) Instead of +, if I use -,/,* they should also work. I was trying something like the above code, but this gives errors because of + and/or *. It takes them as part of the regular expression.
How can I make this work? Please help.