What is the best way to create a new object based on two different objects.
I would like to use java streams.
My two start objects
public class EventA{
Long id;
String name;
...
Long locationID;
}
public class EventB{
Long id
String Name;
...
Long locationID;
}
And my result class
public class Result{
Long locationID;
String eventAName;
String eventBName;
public Result(...){...}
}
I have two object arrays like
List<EventA> eventAList;
List<EventB> eventBList;
I like to get an array of Result objects. Every EventA name should be copied to the resultList. If an EventB at the same location exists I would like to save the name in eventBName.
All I have done so far is
List<Result> resultList = eventAList.stream().map(e -> new Result(e.locationID, e.name, null)).collect(Collectors.toList());
I don't know how to pass the value from EventB to the constructor
EventAandEventB, since they display practically identical properties? You'd then hjave aList<EventCommon>to stream...locationIDor "at the same index ineventAListandeventBList" ?