I have a string say, "1.0+20*30.2-4.0/10.1" which I want to split in such a way that I will have a string array say
strArr = {"1.0", "20", "30.2", "4.0",10.1}
I wrote the following code for this
public class StringSplitDemo {
public static void main(String[] args) {
String str = "1.0+20*30.2-4.0/10.1";
String[] strArr = (str.split("[\\+-/\\*]"));
for(int i=0;i<strArr.length;i++)
System.out.print(strArr[i]+" ");
}
}
Rather than printing the expected output(by me) i.e 1.0 20 30.2 4.0 10.1 it prints
output: 1 0 20 30 2 4 0 10 1
which seems to split the string also around "." even if I didn't include it in the regex pattern.
What I'm missing here? What is the right way to do this?

str.split("[-+/*]")