Valentyn Hruzytskyi :
I have the follow code:
String generalRequest = "4+6*12/3";
String[] operatorsLine = generalRequest.split("[0-9]+");
In result, I have the surplus empty value in operatorsLine
:
"", "+", "*", "/"
Hovewer I desire an outcome:
"+", "*", "/"
How to skip adding ""
value into array, using String.split()
method?
Andronicus :
You can use something like:
String[] operatorsLine = Arrays.stream(generalRequest.split("[0-9]+"))
.filter(s -> !s.isEmpty())
.toArray(String[]::new);