title: Making statistics on database columns through Cursor?
body: <p>I have a <code>Cursor</code> querying a database. I'm interested in getting all numbers from a column, and make some simple statistics on them (e.g., mean, standard deviation and not so much more) which will be shown to the user.</p>
  
  <p>I miss the whole pattern here. Should I store all the values in, say, a <code>int[]</code> array and then make operations? The only way that comes to my mind is something like:</p>
  
  <pre><code>int entries = cursor.getCount();
  int[] array = new int[entries];
  
  for (int i = 0; i &lt; entries; i++) {
      cursor.moveToPosition(i);
      array[i] = cursor.getInt(...);
  }
  </code></pre>
  
  <p>And at this point I'm stuck, because I don't know how to perform stuff (be it even a simple mean) on <code>int[]</code>, without maybe a second <code>for</code>. </p>
  
  <p>As a second chance, I could go like:</p>
  
  <pre><code>int entries = cursor.getCount();
  float mean = 0;
  
  for (int i = 0; i &lt; entries; i++) {
      cursor.moveToPosition(i);
      int newValue = cursor.getInt(...);
      mean = mean + newValue/entries;
  }
  return mean;
  </code></pre>
  
  <p>But it keeps looking bad to me. 
  Moreover, things could get worse if I need to calculate more complex statistics. Could this for loop be avoided somehow? Is there any more correct way?</p>