Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
OpenCSV writing a CSV file using multiple arrays

I have 7 arrays and I want each array to be a column in a CSV file. I'm currently using OpenCSV. But, I haven't figured out a way to generate a CSV file from multiple arrays.

String[] Title = new String[1000];
String[] Starring = new String[1000];
String[] Director = new String[1000];
CSVWriter writer = new CSVWriter(new FileWriter("export.csv"), ',');
String[] entries = Title[1] + Starring[1].split('#');
writer.writeNext(entries);
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Assuming you have a 2D array of String, here's what you can do:

CSVWriter writer = //get csv writer
String[][] lines = //lines
for(String[] lines : lines){
    writer.writeNext(lines);
}
over 4 years ago · Santiago Trujillo Report

0

The writeNext method in openCSV takes an array of String with each element being the value if you have separate arrays you have to build the single array to feed the writeNext. I am not sure if this will work but its worth a shot.

private String[] createRowFromSeparateArrays(String... columns) {
   return columns;
}

And then in your code you would have

for (int i = 0; i < Title.length; i++) {
 writer.writeNext(createRowFromSeparateArrays(Title[i],Starring[i],Director[i]));
}

good luck :)

over 4 years ago · Santiago Trujillo Report

0

You first need to create parallel arrays and cast them into String then Parse the actual array toString. GOOD LUCK

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!