String S= \"multiply 3 add add 3 3 1\"
I want to get two string arrays The one is {\"multiply\", \"add\", \"add\"} Another out is {\"3\",\"3\",\"3\",1}
How can I
You should use Matcher instead of split:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
...
List operators = new ArrayList();
Matcher m = Pattern.compile("add|multiply").matcher(s);
while (m.find()) {
operators.add(m.group());
}
List operands = new ArrayList();
Matcher m = Pattern.compile("[0-9]+").matcher(s);
while (m.find()) {
operands.add(m.group());
}