Note that public String [] split (String regex) accepts a regular expression .
You need to avoid special char .
.
Use String[] test2 = test.split("\\.");
Now you say Java:
"Do not accept .
As a special char .
, Consider it a regular char .
"
Note that regex escaping is done \
, but in Java \
written as \\
.
As suggested in the comments of @OldCurmudgeon (+1), you can use a public static string string (String s) , which "Returns a literal pattern String for the specified string":
String[] test2 = test.split(Pattern.quote("."));
source share