Link to home
Start Free TrialLog in
Avatar of kalyangkm
kalyangkmFlag for United States of America

asked on

Comparing set of records for a substring match to remove duplicate records

Hi Folks,

I will have a list of records like this

1111,abdc,D23
2222,ejdk,D67
3333,eeld,D22
1111,rrrr,Z33
2222,ertu,T22

and I need to drop the duplicate record but the one which comes first rather than later and the output should be

1111,rrrr,Z33
2222,ertu,T22
3333,eeld,D22

My approach is to see if there is any way to compare the substring (the first 4 characters) of the string(in this case considering the entire record as string eg: 1111,abdc,D23). But I am not able to visualize how can I ignore the first record and return only second duplicate record. A sample code would also be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kalyangkm

ASKER

Also can you elaborate  on what exactly you mean by this

"Note that you may be looking to do further processing with each record broken into its fields and so the first part and the last part will probably be different."
Cool, I didnt realize that Linked hashmap would replace the existing key with the key that being inserted if there is a match. Thank You. Could you please eloborate on my above question.
Also can you elaborate  on what exactly you mean by this
All, I meant was that the final desired output is probably not to write those lines to the Java console. I am guessing that you possibly may have further processing that you would like to do, and that it would be useful to keep the "key" still separate from the rest of the fields, or that you want to break up the "entire" record into fields in the first place.

If that is the case, than you probably DON'T need lines 30-36 of the code that I posted. All that does is join the fields back together and print them to the console. Instead, you could take these and directly do the further processing required, etc.

Thank You.
You're welcome!
Thanks for the feedback.