var collectionOfElements = Stream.concat(highs.stream(), lows.stream())
.collect(Collectors.toMap(MyObject::id, Function.identity(), (o1, o2) -> {
return ... // TODO :: merge two objects;
})).values();
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
public class test {
public static void main(String[] args) {
List<Item> listA = new ArrayList<>();
List<Item> listB = new ArrayList<>();
List<Item> coupled = couple(listA, listB);
}
static List<Item> couple(List<Item> listA, List<Item> listB){
return listA.stream()
.peek(itemA -> {
Item complimentary = listB.stream().filter(itemB -> itemB.getId() == itemA.getId()).findFirst().orElse(null);
if (complimentary == null) throw new IllegalArgumentException("Can't find pair");
itemA.setLow(complimentary.getLow());
})
.toList();
}
}
@Getter
@Setter
class Item{
private int id;
private int low;
private int high;
}