title: How to group objects when each object could go in multiple groups?
body: <p>I have a <code>List&lt;Student&gt;</code> where each <code>Student</code> may have multiple hobbies:</p>
  <pre><code>public class StudentData {
      public static List&lt;Student&gt; getData() {
          return Arrays.asList(
              new Student(1, &quot;a1&quot;, 1, Arrays.asList(&quot;cricket&quot;, &quot;football&quot;, &quot;basketball&quot;)),
              new Student(2, &quot;a2&quot;, 1, Arrays.asList(&quot;chess&quot;, &quot;football&quot;)),
              new Student(3, &quot;a3&quot;, 2, Arrays.asList(&quot;running&quot;)),
              new Student(4, &quot;a4&quot;, 2, Arrays.asList(&quot;throwball&quot;, &quot;football&quot;)),
              new Student(5, &quot;a5&quot;, 3, Arrays.asList(&quot;cricket&quot;, &quot;basketball&quot;)),
              new Student(6, &quot;a6&quot;, 4, Arrays.asList(&quot;cricket&quot;)), new Student(7, &quot;a7&quot;, 5, Arrays.asList(&quot;basketball&quot;)),
              new Student(8, &quot;a8&quot;, 6, Arrays.asList(&quot;football&quot;)),
              new Student(9, &quot;a9&quot;, 8, Arrays.asList(&quot;tennis&quot;, &quot;swimming&quot;)),
              new Student(10, &quot;a10&quot;, 8, Arrays.asList(&quot;boxing&quot;, &quot;running&quot;)),
              new Student(11, &quot;a11&quot;, 9, Arrays.asList(&quot;cricket&quot;, &quot;football&quot;)),
              new Student(12, &quot;a12&quot;, 11, Arrays.asList(&quot;tennis&quot;, &quot;shuttle&quot;)),
              new Student(13, &quot;a13&quot;, 12, Arrays.asList(&quot;swimming&quot;))
          );
      }
  }
  </code></pre>
  <p>How to group the students based on hobbies? I tried this below code:</p>
  <pre><code>List&lt;Student&gt; data = StudentData.getData();
  data.stream().collect(Collectors.groupingBy(s -&gt; s.getHobbies().stream()));
  </code></pre>
  <p>It is not giving the right answer.</p>