title: Iterate a list of query results in Java and create objects based on a key value
body: <p>I performed a query and get a result list of this object:</p>
  <pre><code>public MyObject {
        private String key;
        private String value1;
        private Integer value2;
  }
  </code></pre>
  <p>The results looks like this:</p>
  <p>key        value1         value2 <br>
  1              WWW            EEE <br>
  1             WWW            AAA <br>
  2           WWW             EEE</p>
  <p>I would like to iterate this list and create a list of something like this, grouping it by key.</p>
  <pre><code>//first object of the list
  public MyCreatedObject {
        private String key; //1
        private List&lt;Value1&gt; value1List; //WWW, WWW
        private List&lt;Value2&gt; value2List; //EEE, AAA
  }
  
  //second object of the list
  public MyCreatedObject {
        private String key; //2
        private List&lt;Value1&gt; value1List; //WWW
        private List&lt;Value2&gt; value2List; //EEE
  }
  </code></pre>
  <p>I'm tried using stream, iterating and a couple of things but I'm really struggling with this.</p>
  <p>Can someone give me some help?</p>
  <p>Thanks a lot folks</p>