String[][] table = {
{ "fileName", "cadName", "number", "folder_Id", "wC_State",
"legacy_Path", "reverified", "createdBy", "iteration",
"shouldImport" },
{ "abc.sldprt", "abc.sldprt", "abc.sldprt", "098123",
"Working", "C:\\WC", " Empty", "12132019", "2", "True" },
{ "pqr.sldprt", "pqr.sldprt", "pqr.sldprt", "098124", "WIP",
"C:\\WC", " Empty", "12092019", "8", "True" },
{ "jku.sldprt", "jku.sldprt", "jku.sldprt", "094123",
"Released", "C:\\WC", " Empty", "12072019", "13",
"True" },
{ "cmx.sldprt", "cmx.sldprt", "cmx.sldprt", "0981290",
"Development", "C:\\WC", "Yes", "12132018", "19",
"True" },
{ "abc.sldprt", "abc.sldprt", "abc.sldprt", "09812354",
"Working", "C:\\WC", " Empty", "12132019", "3", "True" } };
Asked
Active
Viewed 111 times
-5

Pavel Smirnov
- 4,611
- 3
- 18
- 28

JavaLearn
- 11
- 1
-
1Possible duplicate of [Java API to convert Array to CSV](https://stackoverflow.com/questions/11545991/java-api-to-convert-array-to-csv) – Michal Horvath Apr 16 '19 at 08:18
-
What do you mean by "fetch into"? Do you want to read from or write to a CSV file? – Apr 16 '19 at 08:18
-
I want to write/Store the 2D array elements into CSV file. – JavaLearn Apr 16 '19 at 08:19
-
And how should this CSV look like for this array? – Apr 16 '19 at 08:20
-
fileName,cadName,number,folder_Id,wC_State,legacy_Path,reverified,createdBy,iteration,shouldImport abc.sldprt,abc.sldprt,abc.sldprt,098123,Working,C:\\WC, Empty,12132019,2,True pqr.sldprt,pqr.sldprt,pqr.sldprt,098124,WIP,C:\\WC, Empty,12092019,8,True jku.sldprt,jku.sldprt,jku.sldprt,094123,C,C:\\WC, Empty,12072019,13,True cmx.sldprt,cmx.sldprt,cmx.sldprt,0981290,Development,C:\\WC,Yes,12132018,19,True abc.sldprt,abc.sldprt,abc.sldprt,09812354,Working,C:\\WC, Empty,12132019,3,True – JavaLearn Apr 16 '19 at 08:26
-
Check the duplicate question for answer. If the solutions don't work put your commented code in question itself, with correct formatting, update with the newly gained info too which will prevent down-voting. Welcome to SO. Although your question looks valid at first sight it does not meet SO [minimal site criteria](https://stackoverflow.com/help/asking). Please modify question accordingly to [minimal working example](https://stackoverflow.com/help/mcve). Without posting your code you risk removal of your question. Enjoy SO ;-) – ZF007 Apr 16 '19 at 08:30
2 Answers
1
You can use CSVWriter for this with writeAll() method. It doesn't work on two dimensional array, but it works with Iterable<String[]> or List<String[]>, so you will need to do conversion first.
String[][] table = ...;
List<String[]> convertedTable = Arrays.asList(table);
CSVWriter writer = new CSVWriter(new FileWriter(csvFilename));
writer.writeAll(convertedTable);
writer.close();

Michal Horvath
- 173
- 7
-
Michal Horvath thanks that works,exactly i got what i was looking for !!!! – JavaLearn Apr 16 '19 at 08:38
-
-1
No, you a way to do this would be to use Arrays#toString
(Or a custom toString function), while iterating over the outer array

AleksW
- 703
- 3
- 12