title: How to create an object by accumulating two fields from a list of another object?
body: <p>I have a list of objects Room:</p>
  <pre><code>class Room {
      int guestCount;
      List&lt;String&gt; sunglassBrands;
  }
  </code></pre>
  <p>I want to get the total guests in all the rooms and all of their sunglass brands together like this:</p>
  <pre><code>class Guest {
      int guestCount;
      List&lt;Sunglass&gt; sunglasses;
  }
  
  class Sunglass {
      String brandName;
  }
  </code></pre>
  <p>Now, this is might be a straightforward way to do it:</p>
  <pre><code>AtomicInteger numberOfGuests = new AtomicInteger();
  List&lt;Sunglass&gt; sunglassBrandsList = new ArrayList&lt;&gt;();
  rooms.forEach(
              room -&gt; {
                numberOfGuests.getAndAdd(room.getGuestCount());
                sunglassBrandsList.addAll(
                    room.getSunglassBrands.stream()
                        .map(
                            brand -&gt; {
                              Sunglass sunglass = new Sunglass();
                              sunglass.setBrandName(brand);
                              return sunglass;
                            })
                        .collect(Collectors.toList()));
              });
  Guest guest = new Guest();
  guest.setGuestCount(numberOfGuests.get());
  guest.setSunglassBrands(sunglassBrandsList);
  </code></pre>
  <p>Can this be done in a more elegant way in a single iteration? I think I can use <code>reduce</code> here but I am not quite sure how.</p>