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 can use java 8 groupingBy
.
Map> map = Arrays
.stream(s.split(" "))
.collect(Collectors.groupingBy(e -> e.matches("\\d+")));
System.out.println(map);
The result is:
{false=[multiply, add, add], true=[3, 3, 3, 1]}
You can get operators and operands by:
List operators = map.get(false);
List operands = map.get(true);