title: Filter differences in array
body: <p>I want to filter an array by calculating the differences. Here's the code:</p>
  
  <pre><code>public void compressData(List&lt;Long&gt; array){
      for(int i = 0; i &lt;= array.size(); i++){
          if(Math.abs(array.get(i) - (array.get(i + 1))) &gt;= 100){
              newArray.add(array.get(i));
          }
      }
  }
  </code></pre>
  
  <p>Let's say I have an array of [1, 3, 5, 10]. I want the range between the numbers in array to be at least 5, so in this case the number 3 should be removed. So I want to compare array[i] with array[i + 1]</p>
  
  <p>The code above doesn't work (I know it won't work actually, I think I'm just desperate) because <code>array.get(i - 1)</code> or <code>array.get(i + 1)</code> will give ArrayOutOfIndexException</p>
  
  <p>Thank you in advance =)</p>