title: How to group fields of different type lists using JAVA 8?
body: <p>Here the PHD student who is also a School teacher.
  The common thing between these two objects is their name.
  So I am filtering the data using their name.
  Upto the code I wrote below in the MyMain class, I am able to filter the common records and get the student data.
  But I also want the details of both Student and Teacher and set in the StudentTeacherMapper. Please help me to set the fields in StudentTeacherMapper class. Thank you.</p>
  <pre><code>@Getter
  @Setter
  public class PHDStudent {
                  
      private int studentId;
      private String studentName;
      private String grade;
      private int rank;
                  
  }
         
  @Getter
  @Setter
  public class SCHLTeacher {
              
      private int teacherId;
      private String teacherName;
      private String place;
      private Long Salary;                
  }
      
  @Getter
  @Setter
  public class StudentTeacherMapper {
          
      private int teacherId;
      private String teacherName;
      private String place;
      private Long Salary;
      private int studentId;
      private String studentName;
      private String grade;
      private int rank;
      
  }
  
  
  public class MyMain {
      
      public static void main(String[] args) {
          
          List&lt;SCHLTeacher&gt; teachList = new ArrayList&lt;&gt;();
          List&lt;PHDStudent&gt; studList = new ArrayList&lt;&gt;();
  
          mapStudentTeacherData(teachList, studList);
          
          List&lt;PHDStudent&gt; studentList = teachList.stream().flatMap(
                  teach -&gt; studList.stream().filter(predicate -&gt; predicate.getStudentName().equals(teach.getTeacherName())))
                  .collect(Collectors.toList());
          
          StudentTeacherMapper mapper = new StudentTeacherMapper();
          //set data in mapper
          
  
      }
  
      private static void mapStudentTeacherData(List&lt;SCHLTeacher&gt; teachList, List&lt;PHDStudent&gt; studList) {
          SCHLTeacher teach1 = new SCHLTeacher();
          teach1.setPlace(&quot;Mumbai&quot;);
          teach1.setSalary(100000L);
          teach1.setTeacherId(11);
          teach1.setTeacherName(&quot;Ms.Grace444&quot;);
          SCHLTeacher teach2 = new SCHLTeacher();
          teach2.setPlace(&quot;Delhi&quot;);
          teach2.setSalary(160000L);
          teach2.setTeacherId(22);
          teach2.setTeacherName(&quot;Mr.Paul123&quot;);
          
          teachList.add(teach1);
          teachList.add(teach2);
  
          PHDStudent stud1 = new PHDStudent();
          stud1.setGrade(&quot;A&quot;);
          stud1.setRank(1);
          stud1.setStudentId(11);
          stud1.setStudentName(&quot;Ms.Grace444&quot;);
          PHDStudent stud2 = new PHDStudent();
          stud2.setGrade(&quot;C&quot;);
          stud2.setRank(44);
          stud2.setStudentId(22);
          stud2.setStudentName(&quot;Mr.Paul123&quot;);
          PHDStudent stud3 = new PHDStudent();
          stud3.setGrade(&quot;B&quot;);
          stud3.setRank(12);
          stud3.setStudentId(45);
          stud3.setStudentName(&quot;Mr.X22&quot;);
          
          studList.add(stud1);
          studList.add(stud2);
          studList.add(stud3);
      }
  
  }
  </code></pre>