title: What is the best way to check if ALL values in a range exist in an array? (java)
body: <p>I have the task of determining whether each value from 1, 2, 3... n is in an unordered int array. I'm not sure if this is the most efficient way to go about this, but I created an int[] called range that just has all the numbers from 1-n in order at range[i] (range[0]=1, range[1]=2, ect). Then I tried to use the containsAll method to check if my array of given numbers contains all of the numbers in the range array. However, when I test this it returns false.  What's wrong with my code, and what would be a more efficient way to solve this problem? </p>
  
  <pre><code>public static boolean hasRange(int [] givenNums, int[] range) {
      boolean result = true;
      int n = range.length;
      for (int i = 1; i &lt;= n; i++) {
      if (Arrays.asList(givenNums).containsAll(Arrays.asList(range)) == false) {
             result = false;
       }
     }
      return result;
  }
  </code></pre>
  
  <p>(I'm pretty sure I'm supposed to do this manually rather than using the containsAll method, so if anyone knows how to solve it that way it would be especially helpful!)</p>
  
  <p>Here's where this method is implicated for anyone who is curious: </p>
  
  <pre><code>public static void checkMatrix(int[][] intMatrix) {
      File numberFile = new File("valid3x3") ;
      intMatrix= readMatrix(numberFile);
      int nSquared = sideLength * sideLength;
      int[] values = new int[nSquared];
      int[] range = new int[nSquared];
      int valCount = 0;
  
      for (int i = 0; i&lt;sideLength; i++) {
          for (int j=0; j&lt;sideLength; j++) {
  
              values[valCount] = intMatrix[i][j];
              valCount++;
          }
      }
  
      for (int i=0; i&lt;range.length; i++) {
          range[i] = i+1;
      }
  
      Boolean valuesThere = hasRange(values, range);
  </code></pre>
  
  <p>valuesThere is false when printed.</p>