title: Weird Scenario where I am Missing an element when using ResultSet java inside lambda
body: <p>My ResultSet misses an element when I iterate over the result inside of a lambda function , and assign the results to a variable outside the lambda function. But the same works fine when I declare a variable inside the lambda function, add values to it and return it as part of the function.</p>
  
  <p>I tried placing a count variable and checking both scenarios to see how many times the while loop is run and I confirmed it runs one lesser.</p>
  
  <pre><code>Map&lt;String,String&gt; map = new HashMap&lt;&gt;();
  getTemplate.query("Some Query that returns 38251 elements", (ResultSet rs) -&gt; {
       int count = 0;
       while(rs.next()) {
           count++;
           map.put(rs.getString("val"),rs.getString("val2"));
      }
     //count here is 38250
  });
  map.size() -&gt; 38250 //Missing 1 element
  </code></pre>
  
  <p>But when I do this </p>
  
  <pre><code>Map&lt;String,String&gt; correct = getTemplate.query("Some Query that returns 38251 elements", (ResultSet rs) -&gt; {    
       Map&lt;String,String&gt; map = new HashMap&lt;&gt;();
       int count = 0;
       while(rs.next()) {
           count++;
           map.put(rs.getString("val"),rs.getString("val2"));
      }
     //count here is 38251
     return map;
  });
  correct.size() // 38251 elements
  </code></pre>