I want to split the string when it contains the symbol " " and "-", how can I do that?
Example:
str1 = "2x^3 3x-8";
//Result:
['2x^3', '3x', '8']
CodePudding user response:
A regex split should work here:
String str1 = "2x^3 3x-8";
String[] parts = str1.split("[ -]");
System.out.println(Arrays.toString(parts)); // [2x^3, 3x, 8]