juiceb0xk
juiceb0xk

Reputation: 969

How do I add an item to a String array of type List?

In my code, I am reading in a text file using CSVReader and putting all that into a String array of type list:

CSVReader reader = new CSVReader(new FileReader("addTest.txt"), ',');
List<String[]> myEntries = reader.readAll();
reader.close();

I'm now wanting to add an item to the list, however, when trying to do this via myEntries.add("test" + "," + "test2"), it does not accept it. My goal here is to add an item or items to a new line, then I will use CSVWriter to write it back to file.

How do I go about adding an item, or items to a string array of type list? I've looked around but this problem still has me stumped.

Thank you.

Upvotes: 0

Views: 106

Answers (1)

Scary Wombat
Scary Wombat

Reputation: 44834

The List takes a String array not a comma delimitered string. Can add as

myEntries.add (new String [] {"test", "test2"});

Upvotes: 3

Related Questions