• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please Help - Remove only the duplicated ITEM and NOT the original item that was duplicated.

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a list of items in my list and some of these items are duplicates that were added, at the customer's request because she wanted a message after the add to be displayed to the customer that they could not add a duplicate item to this list. The user then clicks on the duplicate item and we need to remove that duplicate item and not all the original item that match that item number. All I've been seeing when googling is a way to remove ALL duplicate items and not just the record that was added that is considered a duplicate.

My code is below and I need to determine the last duplicate item and then delete that one item by passing in that last duplicate item to my deleteItem() below and keep the original item it duplicated. Any help would be greatly appreciated.

 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Melinda:

How do you know which item is the duplicate?

John.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought I had my problem resolved given an answer I found in the archives of this forum. However, I am still having a problem. I was able to remove the duplicate records from the list using the HashSet since HashSet does not allow duplicates.

However, my question is since I'm setting aSet to a new HashSet using items it would seem that aSet will always find records that will reside in items or am I thinking incorrectly here?

If the object duplicateItems is NOT populated then I just want to delete the items sent to this method but duplicateItems is constantly being populated and I just want it populated if duplicates are found in items.

ANY Help is appreciated. Regards.

In my code here:

 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about



I'll leave it as an exercise for you to figure out how to make this more efficient and more generic (for easier reuse).
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Garrett,

Thanks for the help. I will try it and hopefully this will resolve my problem. Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic