wood burning stoves 2.0*
The moose likes Java in General and the fly likes Data structure to hold information for a file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Data structure to hold information for a file?" Watch "Data structure to hold information for a file?" New topic
Author

Data structure to hold information for a file?

Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
Hi everyone. I wasn't sure whether to put this question on the I/O board or not, it really isn't about I/O specifically...

I have a text file that I have to read information from, and then manipulate and sort the data. I am trying to determine what would be the most efficient way to handle this.

Firstly, I need to figure out what kind of data structure I should store my data in so I can manipulate it. The lines of information are formatted in "columns" like this:

"Account Number","Name","Company","Street","City","State","Zip","Email","Birth Date","Favorites","Standard Payment","Latest Payment","Balance"

and I intend to seperate them by "column". I know how many columns there are, so it would be easy enough to put them in an array. My problem is that I do not know how many lines of information I have so I could not put this information in a 2-D array without first knowing the size of array to create and to do this I have to go through the file and count the number of lines. I could also create a Vector of String arrays, so that the Vector will resize itself every time I add a new String array (line of information seperated by column) with my data in it. Does anyone have an opinion on the most effiecient way to do this?

Help is always appreciated. Thank you!
[ June 12, 2007: Message edited by: Brandi Love ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Seems like a simple JavaBean solution to me.


And then put them in a Collection


Anyway, something like that.


GenRocket - Experts at Building Test Data
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I agree with Gregg about using an ArrayList of Customer objects. On a different note though... using split(",") may be problematic, since it's possible that some fields (e.g. company name) might have commas within them. Parsing comma-separated values can be more complex than it seems at first, thanks to special characters and escape sequences. I recommend using an existing CSV parser library - Steve Ostermiller has a good one, and gives links to others.


"I'm not back." - Bill Harding, Twister
Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
Thanks for the advice, guys! I'll give it shot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data structure to hold information for a file?