title: How reduce not used capacity of ArrayList
body: <p>After some convert <code>ArrayList</code> have 3 elements, <code>ArrayList</code> size is biggest then 3. So <code>NullPointerException</code> occurs when uses <code>forEach</code> circle.</p>
  
  <p>How does avoid this situation? I mean without <code>!=null</code> checks.</p>
  
  <p>Example: </p>
  
  <pre><code>List&lt;String&gt; busesIdToRemove = driverWrapper.getBusesIdToRemove(); 
  </code></pre>
  
  <p>List contains id's those entities, which will be remove. Error occurs in place: </p>
  
  <pre><code>for (String id : busesIdToRemove) { 
  Long longId = Long.valueOf(id); //here. Because id is null ... 
  } 
  </code></pre>
  
  <p>But, actually, list contains only elements with not empty values. </p>
  
  <p>For example [index, value]. </p>
  
  <p>1, "41"; </p>
  
  <p>4, "50" ...</p>
  
  <p>Info about elements with indexes [0],[2],[3] is absent in debugger, and return null for <code>get(0)</code> e.g. method. </p>
  
  <p>Problem resolved with: arrayList.removeAll(Collections.singleton(null));</p>