title: Java GroupBy with 3 classes and Enum
body: <p>I'm a beginner in Java.I have an issue that I can't seem to solve.</p>
  <p>I have 3 classes,</p>
  <pre><code>public class Pet {
  public String petname;
  Type type; }
  
  public class Owner {
  public String name;
  public int age; }
  
  public class PetStore {
  public Owner owner;
  public ArrayList&lt;Pet&gt; pets;}
  </code></pre>
  <p>my output is right now:</p>
  <pre><code>Owner Mike (39) owns the animals: [Cat: Sunny, Rat: Bean, Cat: Milk, Dog: Boomer]
  </code></pre>
  <p>But I want a different output, like this:</p>
  <pre><code>Owner Mike (39) owns the animals: [Cats: Sunny, Milk], [Rat: Bean], [Dog: Boomer]
  </code></pre>
  <p>How can I achieve this? Can I use Stream and groupBY?</p>
  <p>-------------- Edit ---------------------</p>
  <p>I have a Program Class where I generate random data. I want to user the groupBy with the Petstore List.</p>
  <pre><code>public static List&lt;PetStore&gt; getAllAnimal(){
  
      return petstore = IntStream.range(0, 20)
              .mapToObj(i -&gt; new PetStore(new Person(getOwnerName(),getOwnerAge()), new ArrayList&lt;Pet&gt;(getList())))
              .collect(toList());
  }
  
  public static ArrayList&lt;Pet&gt; getList() {
      int randomSize = 1 + rand.nextInt(5);
      return animals = IntStream.range(0 , randomSize)
              .limit(randomSize)
              .mapToObj(i -&gt; new Pet(PetNameGenerator.getName(), rand()))
              .collect(toCollection(ArrayList::new));
  
  }
  </code></pre>
  <p>Thanks for the help.</p>