chepe lucho :
public class Bill {
private Long code;
public Bill(Long code) {
this.code = code;
}
// setters and Getters
}
class Detail {
private BillId billId;
public Detail(BillId billId) {
this.billId = billId;
}
// setters and Getters
}
class BillId {
private Long number;
private Long code;
public BillId(Long number, Long code) {
this.number = number;
this.code = code;
}
// setters and Getters
}
Ahora tengo
List<Bill> listBill = new ArrayList<>();
listBill.add(new Bill(1L));
listBill.add(new Bill(2L));
listBill.add(new Bill(3L));
listBill.add(new Bill(4L));
listBill.add(new Bill(5L));
listBill.add(new Bill(6L));
List<Detail> listDetail = new ArrayList<>();
listDetail.add(new Detail(new BillId(1000L, 10L)));
listDetail.add(new Detail(new BillId(1000L, 2L)));
listDetail.add(new Detail(new BillId(2000L, 30L)));
listDetail.add(new Detail(new BillId(2000L, 4L)));
listDetail.add(new Detail(new BillId(3000L, 50L)));
listDetail.add(new Detail(new BillId(3000L, 6L)));
Ahora necesito un new List
llevaron los artículos en listBill
donde algún elemento no coincide con algún elemento delistDetail
detail.getBillId ().getCode() not match with bill.getCode()
Lista de espera Lo sentimos para el Nuevo!
newListBill.add(new Bill(1L));
newListBill.add(new Bill(3L));
newListBill.add(new Bill(5L));
tsolakp:
El uso de la API de flujo:
listBill.stream()
.filter( b -> !listDetail.stream()
.anyMatch( d -> d.getBillId().getCode() == b.getCode() ) )
.collect( Collectors.toList() );