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?
You can use something like:
String[] operatorsLine = Arrays.stream(generalRequest.split("[0-9]+"))
.filter(s -> !s.isEmpty())
.toArray(String[]::new);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With