wood burning stoves 2.0*
The moose likes Groovy and the fly likes CSV File creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "CSV File creation" Watch "CSV File creation" New topic

CSV File creation

Bill Dowd

Joined: Aug 17, 2012
Posts: 4
Hi all,

I'm a relative newcomer to Groovy/Java and have a question about efficiently outputting data to a .csv file. Basically, as my simulation model runs, I save key information in a list. For example, I track tasks undertaken by agents, so I save ID, duration, and action. I end up with a long list that is divisible by 3, but has a number of elements in it. I use the following code to output it into a 3 column csv file:

Essentially, I take the first three elements of my list, create a list that represents a row, add it to a list of maps, and then write to the csv file one row at a time. It produces perfect output, but it takes forever (these lists have thousands of elements in them). It's much faster to just write the original list to CSV, but then I end up with one row rather than a three-column table. I can always process the data in something that I'm more familiar with, like Stata, but I figured I'd ask about more efficient ways to do this. Thanks in advance for your thoughts!

Bill Dowd

Joined: Aug 17, 2012
Posts: 4
I figured out a way around it. Thanks, all!
It is sorta covered in the JavaRanch Style Guide.
subject: CSV File creation
Similar Threads
What is the best way to store List<List<String>> in database?
data on specific place in text file with xml or without
save my application
Generate CSV from Resultset
Can we use jsp stuff in onklick events