title: How to find duplicates in a list?
body: <p>I have a list of <strong>unsorted</strong> integers and I want to find those elements which have duplicates.</p>
  
  <pre><code>val dup = List(1,1,1,2,3,4,5,5,6,100,101,101,102)
  </code></pre>
  
  <p>I can find the distinct elements of the set with dup.distinct, so I wrote my answer as follows.</p>
  
  <pre><code>val dup = List(1,1,1,2,3,4,5,5,6,100,101,101,102)
  val distinct = dup.distinct
  val elementsWithCounts = distinct.map( (a:Int) =&gt; (a, dup.count( (b:Int) =&gt; a == b )) )
  val duplicatesRemoved = elementsWithCounts.filter( (pair: Pair[Int,Int]) =&gt; { pair._2 &lt;= 1 } )
  val withDuplicates = elementsWithCounts.filter( (pair: Pair[Int,Int]) =&gt; { pair._2 &gt; 1 } )
  </code></pre>
  
  <p>Is there an easier way to solve this?</p>