Splitting a Java String return empty array?

You must escape the dot.

String columnArray[] = a.split("\\.");

Note that String#split takes a regex.

You need to escape the special char . (That means "any character"):

 String columnArray[] = a.split("\\.");

(Escaping a regex is done by \, but in Java, \ is written as \\).

You can also use Pattern#quote:

Returns a literal pattern String for the specified String.

String columnArray[] = a.split(Pattern.quote("."));

By escaping the regex, you tell the compiler to treat the . as the string . and not the special char ..

Tags:

Java

Split