Skip to content
Advertisement

parsing csv file dealing with empty value java

I am new to java and practicing parsing csv file. I’ve figured out how to parse and use a constructor to create an instance. However, there are empty strings in my csv file, and the console just throw IllegalArgumentException: No enum constant to me.

I’ve referred to:

  1. enum valueOf IllegalArgumentException: No enum const class
  2. Parse CSV file in java, and delaing with empty values

Unfortunately, it doesn’t work. When it comes to the Person with empty Profession, the program breaks. Do I need to fill some string like “NONE” for matching the enum, or there is any way to deal with this? Any help or hint is highly appreciated.

Here is my Profession for example:

JavaScript

Here is how my csv file looks like:

JavaScript

Here is the parsing code:

JavaScript

and the parsed line looks like:

JavaScript

Advertisement

Answer

Do it as follows:

JavaScript
Advertisement