title: Get size of an Iterable in Java
body: <p>I need to figure out the number of elements in an <code>Iterable</code> in Java.
  I know I can do this:</p>
  
  <pre><code>Iterable values = ...
  it = values.iterator();
  while (it.hasNext()) {
    it.next();
    sum++;
  }
  </code></pre>
  
  <p>I could also do something like this, because I do not need the objects in the Iterable any further:</p>
  
  <pre><code>it = values.iterator();
  while (it.hasNext()) {
    it.remove();
    sum++;
  }
  </code></pre>
  
  <p>A small scale benchmark did not show much performance difference, any comments or other ideas for this problem?</p>