I have a list of unsorted integers and I want to find those elements which have duplicates.
val dup = List(1,1,1,2,3,4,5,5,6,100,101,101,102
A bit late to the party, but here's another approach:
dup.diff(dup.distinct).distinct
diff gives you all the extra items above those in the argument (dup.distinct), which are the duplicates.
diff
dup.distinct