title: How do I selectively remove values from my arraylist based on a condition?
body: <p>I have seen the answer a <a href="https://stackoverflow.com/questions/20602388/remove-elements-from-arraylist-based-on-a-condition">here</a> and I am not sure it answers my issue. So I have an arraylist of Float type containing a bunch of numbers. I wish to remove all the numbers which are 30 more or less than the previous value. So, I am comparing <code>'n'</code> and <code>'n+1'</code> and removing <code>'n+1'</code> <code>if (n+1)&gt;(30+n)</code> and vice versa. I have written the following code but my solution isn't working. </p>
  
  <pre><code>for(int i = 0; i&lt;hr_list.size()-1; i++)
      {
          Float x= hr_list.get(i);
          Float y = hr_list.get(i+1);
  
          if(y&gt;(x+30.0f)||y&lt;(x+30.0f))
          {
              hr_list.remove(i+1);
          }
      }
  </code></pre>