title: Finding duplicate numbers in array
body: <p>The problem with this code is that it will print out 5 9 9, instead of just 5,9. Because there is a third 9 in the array. What am I missing?</p>
  
  <p>Edit: I need to write a function that will get the duplicates from the array given. I am trying to do this, but it is printing out a 5,9,9 instead of 5,9.</p>
  
  <p>Edit 2: Well I figured it out after reading up on HashSet and got it to work using the code below. I hope this can help others with the same problem.</p>
  
  <pre><code>import java.util.HashSet;
  
  
  public class Duplicator {
  
  /**
   * @param args
   */
  public static void main(String[] args) {
  
      int[] a = {3,5,5,8,9,9,9};
  
      HashSet&lt;Integer&gt; hash = new HashSet&lt;Integer&gt;();
  
      for(int i = 0; i &lt; a.length; i++){
  
          for(int j = i+1; j&lt; a.length; j++){
  
              if(a[i] == a[j]){
  
                  hash.add(a[i]);
  
              }
          }
  
  
      }
  
      System.out.println(hash);
  
      }
  }
  </code></pre>