0

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.

2

1 Answer 1

3

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

myEntries.add (new String [] {"test", "test2"});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.