//***************************************************************************
// Read any size CSV file into a list of String arrays 
//***************************************************************************
import java.io.*;
import java.util.*;

public class ReadCSVintoList 
{     
    public static void main(String[ ] args)
    {  
        String filename	       = "../zAnalytics/dataset3.csv";	    //CSV input file
        List<String[]> records = new ArrayList<>();                 //list of string arrays to hold the file data                 

        readCSV(filename, records);
        printCSV(records);
    }
    public static void readCSV(String filename, List<String[]> records)
    {
        try 
        { 
            FileReader file    = new FileReader(filename);
            BufferedReader buf = new BufferedReader(file);

            String line;
            while ((line = buf.readLine()) != null) 
            {
                String[] elements = line.split(",");        //split on commas
                records.add(elements);                      //add String array to list
            }  
        }
        catch(Exception e) 
        {
            System.out.println(e);					//print the exception
            e.printStackTrace();					//print stack trace
        }
    }
    public static void printCSV(List<String[]> records)
    {
        for (String[] record : records) 
        {
            System.out.println(Arrays.toString(record));
        }
    }
}