title: How to check if array element is null to avoid NullPointerException in Java
body: <p>I have a partially nfilled array of objects, and when I iterate through them I tried to check to see whether the selected object is <code>null</code> before I do other stuff with it. However, even the act of checking if it is <code>null</code> seem to through a <code>NullPointerException</code>. <code>array.length</code> will include all <code>null</code> elements as well. How do you go about checking for <code>null</code> elements in an array? For example in the following code will throw an NPE for me.</p>
  
  <pre><code>Object[][] someArray = new Object[5][];
  for (int i=0; i&lt;=someArray.length-1; i++) {
      if (someArray[i]!=null) { //do something
      } 
  }
  </code></pre>