I have data in the below format:

```
   List<ArrayList<String>>

```

I want to write it to CSV. Below is my code:

```
private static void writeToCSV(List<ArrayList<String>> csvInput) throws IOException{

String csv = "C:\\output.csv";
CSVWriter writer = null;

try {
    writer = new CSVWriter(new FileWriter(csv));
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

for(ArrayList<String> each: csvInput){
    writer.writeNext(each);
}

writer.close();
}//end of writeTOCSV

```

The method 'writeNext' allows only String[ ] as it's argument. When I try to type cast 'ArrayList each' into String[] using an Object[ ] as shown below, I am getting run time type casting error:

```
   Object[] eachTemp = each.toArray();
   writer.writeNext((String[]) eachTemp);

```

Could anyone please tell me where I am going wrong?