title: Using a for loop in Java, do I have to specify not null?
body: <p>Well, I have a have a primitive array of objects, and because I can't remove them from the array, I instead change the object's position in the array to null. However, if I want to iterate over each object in the array, in the following way:</p>
  
  <pre><code>for (Derp derp : derps){
       derp.herp++;
  }
  </code></pre>
  
  <p>Do I have to do something like this?</p>
  
  <pre><code>for (Derp derp : derps){
       if (derp != null){
       derp.herp++;
       }
  }
  </code></pre>
  
  <p>Or would it be fine the first way I had it? Will the for loop 'know' that it only has to iterate over the Derp objects, and not the null objects, because I've declared it as a Derp object? Or perhaps it just treats it as a Derp object because I've said it would be, and it would cause an error when it tries to iterate over a non-Derp object? Or is null still a Derp object, just one that is null? Which is it, and what code can I use?</p>
  
  <p>Alternatively, how can I remove an object from a primitive array and not leave a null object and actually shorten the length of the primitive array?</p>