I have 2 Lists of type string:
- List1 has items – item1, item2, item3
- List2 has items – item2, item3
Now I need to compare both lists and remove the duplicated items from List1. The modified List1 should have just one item, which is “item1”.
foreach loops may work, but what I want to know is there any inbuilt method which does this?
EDIT
Thanks for the answers guys. I was just thinking what would be the case if I wanted to add the missed out items into the List. So just raised another question similar to this.
TIA!
I suspect the best approach to use here would be to put the second list into a hash first, i.e.
This avoids having O(n*m) performance, instead being O(n+m)
Example: