title: Is there a way to access a value of a JSON document from mongodb which is inside an ArrayList?
body: <p>I have a code snippet that looks like this</p>
  <pre><code>MongoDatabase db = DbConnection.getDbConnection(); // connection is successfully made
  MongoCollection collection = db.getCollection(&quot;candidates&quot;); collection called candidates in the database
  
  ArrayList&lt;String&gt; newList = new ArrayList&lt;&gt;();
  
  FindIterable&lt;Document&gt; findIterable =  collection.find()
      .projection(fields(include(&quot;CandidateId&quot;), excludeId()));
  
  for(Document document:findIterable) {
    newList.add(String.valueOf(document));            
    }
  System.out.println(newList);
  </code></pre>
  <p>The output looks like this</p>
  <pre><code>[Document{{CandidateId=1}}, Document{{CandidateId=2}}]
  </code></pre>
  <p>Is there any way I could get an arrayList that looks like this, where i only need the value of the  CandidateId field</p>
  <pre><code>[1,2]
  </code></pre>