aspose file tools*
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
JavaRanch » Java Forums » Languages » Groovy
Bookmark "CSV File creation" Watch "CSV File creation" New topic
Author

CSV File creation

Bill Dowd
Greenhorn

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
Bill Dowd
Greenhorn

Joined: Aug 17, 2012
Posts: 4
I figured out a way around it. Thanks, all!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: CSV File creation