The CSV format is generally handled with fixed column or row positions. If fixed row and column positions cannot be guaranteed, then you can look at handling the headers to determine the position of the row.
As a general rule, it's going to be much simpler to use a purpose built CSV parser, especially if you do not control the data or output format of the CSV file you are using, as the CSV format has a range of potential corner cases (e.g., commas in the data fields) that cannot be properly handled by String#split()
. Two frequently mentioned open-source Java libraries for parsing CSV files are SuperCSV and OpenCSV. OpenCSV can handle parsing CSV files with headers into Java bean objects. SuperCSV can handle both that functionality and parsing a CSV file with headers into a map.
Other CSV libraries can be found listed for this question, this question, and this question.