• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data structure to hold information for a file?

 
Brandi Love
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems like a simple JavaBean solution to me.


And then put them in a Collection


Anyway, something like that.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brandi Love
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the advice, guys! I'll give it shot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic