title: java convert resultset to a list
body: <p>I want to convert my Resultset to List of object . This is my query:</p>
  
  <pre><code> String querystring1= "SELECT userID, privilege"
                 + "FROM dbo.User order by userID, privilege";
  
  
   userID  privilege
   ------------------
   1001    read 
   1001   write
   1001   execute 
   1001   delete
   1006    execute 
   1006    read
   1006    write
   1007   read
   1007    write
  </code></pre>
  
  <p>I have a class User defined like :</p>
  
  <pre><code>public class User {
     private int userID;
     private List&lt;String&gt; userPrivelege;
  }
  </code></pre>
  
  <p>I want to have as an output to a list of Users, and this is my implemented code:</p>
  
  <pre><code>   String previousId = null;  
     List&lt;String&gt; PrivList= new ArrayList&lt;String&gt;();
     List&lt;User&gt; allUserList= new ArrayList&lt;User&gt;();
  
     while(result_set.next()) {
        String userID = result_set.getString("userID");
        String privilege = result_set.getString("privilege");
        if (previousId == null) { // first time
           User user = new User();
           PrivList.add(privilege);
           previousId=userID;
        } else if (previousId.equals(userID) {
           PrivList.add(privilege);
        } else {
           user.setUserPrivilege(PrivList);
           allUserList.add(user);
           PrivList.clear();
           previousId=null;
        }
     }
  </code></pre>
  
  <p>The problem is,  other than the first user object created, all the next one are always missing the first value which means user 1006 will have 2 privileges other than 3.
  Any idea?</p>