Got a String
:
String s = "1+2*(30+4/2-(1+2))*2+1";
Got method
to split a string:
public void convertString(String s) {
String[] arr = s.split("(?<=[\\d.])(?=[^\\d.])|(?<=[^\\d.])(?=[\\d.])");
}
problem is:
Output:
[1, +, 2, *(, 30, +, 4, /, 2, -(, 1, +, 2, ))*, 2, +, 1]
//here round brackets store in the same cell with next symbol or prev symbol *(, ))*,
expected output:
[1, +, 2, *, (, 30, +, 4, /, 2, -, (, 1, +, 2, ), ), *, 2, +, 1]
// here round brackets store in a separate arr cells
I need to store round brackets in the separate array cells.
How to achieve it?