I would like to export a multidimensional array to a CSV file. I'm able to get a set array to export, but am struggling with a growing array
Here is what I have so far:
String[][] data = new String[][] {
new String[]{"quick","brown","fox"},
new String[]{"apple","banana","cherry"},
new String[]{"quick","brown","fox"}
};
for(int i=0; i<data.length; i++) {
//first line prints "quick", "brown", "fox" etc
writer.writeNext(data[i]);
}
Now growing from my code, I need to be able to add arrays to "data".
For instance, if I have:
String[] abc = new String[] {"a","b","c"};
String[] def = new String[] {"d","e","f"};
...
and I don't know how many of these string arrays I'll have, researching tells me that I'll need to add these to a ArrayList. So I came up with something like this:
List<String[]> stockList = new ArrayList<String[]>();
stockList.add(abc);
stockList.add(def);
// could potentially add more
String[] stockArr = new String[stockList.size()];
stockArr = stockList.toArray(stockArr);
for(int i=0; i<data.length; i++) {
writer.writeNext(stockArr[i]);
Log.i("loop", "here: " + data[i]);
}
except writeNext cannot be applied to a java string.
Overall, it seems like I need to have an ArrayList of a string arrays. Then at the end, convert that ArrayList into an Array and not lose the string arrays?
Would appreciate any help, thanks!