• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Merging rows with same ID together with dynamic headers with CSV

 
Jas Get
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Help, I just can't figure it out. A friend helped with this but could not figure it our either.

I am trying to merge CSV rows together that have the same ID number, but have different values in the fields. I receive csv files weekly that can have different header names and sizes.

For example,

Read in this CSV file:

ID NAME PHONE EMAIL
22 John 555-1111
22 John 555-2222 john@aol.com
44 Bill 555-9999 Bill@aol.com

Should return:

ID NAME PHONE EMAIL PHONE0
22 John 555-1111 john@aol.com 555-2222
44 Bill 555-9999 Bill@aol.com


But it returns:

ID NAME PHONE EMAIL PHONE0 EMAIL0
22 John 555-1111 Bill@aol.com 555-2222 john@aol.com
44 Bill 555-9999


It does work correctly when I have this file:
ID NAME PHONE EMAIL
22 John 555-1111 john@aol.com
22 John 555-2222 john@aol.com
44 Bill 555-9999 Bill@aol.com





Here is my Code:
 
Jas Get
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is just some simple test data. Sometimes there are 20 headers with 80,000 records so I was wondering if this is the most efficient way to process the records.

Thank you
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic