• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Data structure to hold information for a file?

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems like a simple JavaBean solution to me.


And then put them in a Collection


Anyway, something like that.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the advice, guys! I'll give it shot.
 
What a show! What atmosphere! What fun! What a tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic