I need to merge 2 lists List<Phone>
, and List<PhoneTwo>
, into one combined object Combined
, in the Combined
only has one field, which is phone
[
{
"phones": [
{
"id": 1,
"phone": "44444444"
},
{
"id": 2,
"phone": "5555555"
}
],
"phonesTwo": [
{
"id": 1,
"phone": "77777777"
},
{
"id": 2,
"phone": "66666666"
}
],
"combined": null
}
]
The Expected result is:
[
{
"phones": [
//data removed for brevity
],
"phonesTwo": [
//data removed for brevity
],
"combined": [
{
"phone": "44444444"
},
{
"phone": "5555555"
},
{
"phone": "77777777"
},
{
"phone": "77777777"
}
]
}
]
Trying to use flatmap, but stuck somewhere here, how should i proceed?
employee.getPhones()
.stream()
.flatMap(employee.getPhonesTwo().stream()
.map(two -> {
Combined combined = new Combined();
//not sure what to do here
})).collect(Collectors.toList());