title: Java, Return true if array contains duplicate values
body: <p>I am trying to have a method (duplicates) return true if a given array called x (entered by user in another method), contains duplicate values.  Otherwise it would return false.  Rather then checking the entire array, which is initialized to 100, it will check only the amount of values entered, which is kept track of with a global counter: numElementsInX.</p>
  
  <p>What is the best way to accomplish this?</p>
  
  <pre><code>public static boolean duplicates (int [] x)
  </code></pre>
  
  <p>I am prompting for user data like so:</p>
  
  <pre><code>public static void readData (int [] x, int i){
  
      Scanner input = new Scanner(System.in);
      System.out.println("Please enter integers, enter -999 to stop");
  
      while (i &lt;= 99) {
          int temp = input.nextInt();
              if(temp == -999){
                  break;
              }
              else {
                  x[i++]=temp;
              }
  
      // else
  
  }//end while
          printArray(x,i);
  
  
  }//end readData
  
  public static void printArray(int [] x, int numElementsInX){
  
  int n = numElementsInX;
  
  for (int i = 0; i &lt; n; i++){
      System.out.print(x[i] + " ");
  
  
  }//end for
          System.out.println();
  }//end printArray
  </code></pre>
  
  <p>I am sure there is a better way to do this, but this is how I have been taught so far.</p>