have to implement a static-public method named "csvToList" in the class "Functionality.java". The method gets a string as input parameter and returns a LinkedList<String[]>.
Signature: csvToList(String path) : LinkedList<String[]>
My problem is to implement this : The method reads a CSV file in the path. Each single line is divided into two parts. The two parts are always separated by a comma. The two parts are normalized by removing any spaces at the front and back, and stored in a string array. This two-pair in string[] is added to the list. The list with the two-pairs is to be returned.
The algorithm must meet the following requirements:
The first row should not be read in, because it contains only the column information.
The normalized entries of a line should be in a string array.
The individual elements of the lines should not contain any spaces in the string array.
If an IOException is thrown when reading the file, null should be returned. Use try & catch for this.
My code:
public static String [] csvToList(String path) { String fileName = "c:\\test\\csv\\country.csv"; String splitBy = ","; try { BufferedReader br = new BufferedReader(new FileReader(country.csv)); String line; String line1=null; while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); } catch (IOException e) { e.printStackTrace(); } return null;