How to import CSV File using String.split(",") without having the array shortened due to blank fields?

csv, java, split, string

Solution

There is another overload of `split` that achieves that:

string.split(",", -1);

Problem

Currently, when I import the CSV file line by line with `String.split(",")` if there is a line that looks like `"foo,,bar,,fizz,,,"` the method returns an array of length 5, which looks like `["foo", "", "bar, "", "fizz"]`. How do I get the method to return an array of length 8 being `["foo", "", "bar", "", "fizz, "", "", ""]`?

Original source