String.split
takes a regular expression as argument.
This means you can alternate whatever symbol or text abstraction in one parameter in order to split your String
.
See documentation here.
Here's an example in your case:
String toSplit = "a+b-c*d/e=f";
String[] splitted = toSplit.split("[-+*/=]");
for (String split: splitted) {
System.out.println(split);
}
Output:
a
b
c
d
e
f
Notes:
- Reserved characters for
Pattern
s must be double-escaped with\\
. Edit: Not needed here. - The
[]
brackets in the pattern indicate a character class. - More on
Pattern
s here.