title: How to calculate data from MongoDB through Java?
body: <p>I have a problem using MongoDb through Java
  I'd like to show my piece program</p>
  
  <pre><code>DBCollection coll = db.getCollection("datatrain");
  DBCursor cursor = coll.find();
  Iterator&lt;DBObject&gt; dbo = cursor.iterator();
  while (dbo.hasNext()) {
    double column1 = (double) dbo.next().get("column1");
    System.out.println(column1); //result show as I expected
  }
  System.out.println(column1); //only first document printed and local variable error
  </code></pre>
  
  <p>Is there any method to get data in all document outside <em>while</em>? I know the <strong>column1</strong> inside <em>while</em> is a list and I want to use it outside <em>while</em> to become array. I've tried use <em>toArray</em> but it always give me error. Any good manner to use toArray in program?</p>