title: String[] length count
body: <p>I am declaring a String array as:</p>
  
  <pre><code>String[] items = new String[10];
  items[0] = "item1";
  items[1] = "item2";
  </code></pre>
  
  <p>How can I find length of items in an efficient way that it contains only 2 elements. <code>items.length</code> returns 10.</p>
  
  <p>I am running a loop already which runs to its length. I want to so something with this code without adding new code/loop to count number of not-null elements. What can I replace with items.length</p>
  
  <pre><code>for (int i = 0; i &lt; items.length; i++) {
  ...
  }
  </code></pre>