title: Java 8 streams : Combine properties of two objects which are in ArrayLists into an ArrayList of a third object type
body: <p>I'm new to the Java 8 streams and would appreciate some help in learning. </p>
  
  <p>I have an Arraylist  of User objects and and Arraylist of UserCompany objects. The User object has a user_id and associated user information  The UserCompany list has the user's Company object but only has the user_id of the User. 
   I would like to create a third object called UserCompanyView that is a combination of the User object and the Company object using Java 8 streams. 
     I have only been able to find examples of two arrays being concatenated or merged , like,:</p>
  
  <pre><code> Stream.of(list1, list2)
  .flatMap(x -&gt; x.stream())
  .collect(Collectors.toList());
  </code></pre>
  
  <p>but nothing where specific properties of the individual lists are used to create a third Object.  </p>
  
  <p>the code should :  </p>
  
  <p>1) iterate through the  UserCompany list  </p>
  
  <p>2)Check if the UserCompany user_id matches the User list user_id  </p>
  
  <p>3) if 2 is true , create a UserCompanyView object using the User and the UserCompany  </p>
  
  <p>4) Add the UserCompanyView  from 3 to a new List and return it.  </p>
  
  <p>Thanks for viewing this post and taking time to reply </p>