title: Newbie having trouble with arrays
body: <p>I have been studying Java by myself for a few weeks but I have become completely stuck in one challenge question I found online. I have thouroughly searched Google to see if anyone else asked it but I can't seem to find anything. Since I don't have any teachers, I was wondering if anyone on StackOverflow could help me out.</p>
  
  <p>I am having an issue with one of my methods because it keeps failing my test cases and I'm not sure what exactly is making it go wrong.</p>
  
  <p>Basically, if I input an array like [2, 8, 3, 9, 7], I want it to come out like [2, 3, 7, 8, 9]. However, with this poorly written method I have here, I keep getting the extra element at the beginning, which results in [2, 2, 3, 7, 8, 9]. My specific goal with this method is to find and return an array that contains all values greater/equal to "high" and less than/equal to "low" , including duplicates. The length of this array should be the same as the # of elements in the 'range', hence the method name.</p>
  
  <p>I just wanted to be properly directed towards the next step that I should be taking to eliminate this first element issue. I know that the code is probably awful and messy, so please bear with me.</p>
  
  <p>Thank you; all help is appreciated!</p>
  
  <pre><code>public static int[] range(int[] a, int low, int high) {
    if (a == null || a.length == 0) {
       throw new IllegalArgumentException();
    }
  
    int[] newArr = new int[0];
    if (low &lt;= high) {
       if (a.length == 1 &amp;&amp; low &gt;= a[0] &amp;&amp; high &lt;= a[0]) {
          return a;
       }
  
       for (int i : a) {
          if (i &gt;= low &amp;&amp; i &lt;= high) {
             int[] duplicate = new int[(a.length + 1)];
             int count = 0;
             for (int num : a) {
                duplicate[count] = num;
                count++;
             }
             duplicate[count] = i;
             return duplicate;
          }
       }
    }
    if (newArr.length &gt; 1) {
       Arrays.sort(newArr);
    }
    return newArr;
  </code></pre>
  
  <p>}</p>