title: How to select duplicate values from a list in java?
body: <p>For example my list contains {4, 6, 6, 7, 7, 8} and I want final result = {6, 6, 7, 7}</p>
  
  <p>One way is to loop through the list and eliminate unique values (4, 8 in this case).</p>
  
  <p>Is there any other efficient way rather than looping through list ? I asked this question because the list that I am working is very large ?
  My code is </p>
  
  <pre><code>List&lt;Long&gt; duplicate = new ArrayList();
  for (int i = 0; i &lt; list.size(); i++) {
       Long item = (Long) list.get(i);
       if (!duplicate.contains(item)) {
            duplicate.add(item);
           }
       }
  </code></pre>