title: Is it good to create an object inside a loop?
body: <p>I am trying to get data from db and present that data in json object. to represent the data into json object i'm trying to iterate from resultset object and add result into a list. But is it good to create a class object inside while loop. In my case it is going to create more than 100 objects. </p>
  
  <pre><code>Emp emp;
  List&lt;Emp&gt; empList = new ArrayList&lt;Emp&gt;();
  while(rs.next()){
      emp = new Emp();
      emp.setEMPLOYEE_ID(rs.getString("EMPLOYEE_ID"));
      emp.setFIRST_NAME(rs.getString("FIRST_NAME"));
      emp.setLAST_NAME(rs.getString("LAST_NAME"));
      empList.add(emp);
  }
  System.out.println(empList.size());
  ObjectWriter ob = new ObjectMapper().writer().withDefaultPrettyPrinter();
  json = ob.writeValueAsString(empList);
  </code></pre>