This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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!
I agree. Here's the link:
subject: CSV File creation
It's not a secret anymore!