'comparing two different type of List using Java8 [closed]

class Person{

private String name;
private String address;
private int id;
private int uniqueIdentificationNumber;

}


class Company{

private String name;
private String address;
private int id;
private int uniqueIdentificationNumber;
private String company;
}


class Test{

public static void main(String[] args)
{
     List<Person> persons = new ArrayList<>();
      Person p1 = new Person();
      p1.setName("ABC");
      p1.setAddress("US");
      p1.setId(1);
      p1.setUniqueIdentificationNumber(11);
     
      Person p2 = new Person();
      p2.setName("PQR");
      p2.setAddress("US");
      p2.setId(2);
      p2.setUniqueIdentificationNumber(22);
     
      persons.add(p1);
      persons.add(p2);  

     List<Company> companies = new ArrayList<>();
     
     Company c1 = new Comapny();
      c1.setName("ABC");
      c1.setAddress("US");
      c1.setId(3);
      c1.setUniqueIdentificationNumber(44);
      c1.setCompany("C1")

     Company c2 = new Comapny();
      c2.setName("ABC");
      c2.setAddress("US");
      c2.setId(1);
      c2.setUniqueIdentificationNumber(11);
      c2.setCompany("C2");

      companies.add(c1);
      companies.add(c2)

}
}

I want to compare two different object types of lists (companies and persons) with Java8 Stream API and return the customer object which is matching with Id and setUniqueIdentificationNumber. i.e here in this case it should retun c2.

Can anyone help on this



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source