누군가가 어쩌면 어떤 생각을 가지고 있을까요? 이것을 stream()
으로 어떻게 바꿀 수 있습니까? 내가 아는두 foreach를 하나의 스트림으로 변경하십시오.
for (Customer customer : customers) {
if (customer.getProducts() != null && customer.getProducts().getProduct() != null) {
for (Product product : customer.getProducts().getProduct()) {
if (product.getId().equals(productId)) {
return Optional.of(product);
}
}
}
}
, 내가로 교체 할 수있는 두 번째 foreach는 : 하나 개의 스트림으로
customer.getProducts().getProduct().stream().filter(a -> a.getId().equals(productId)).findAny();
하지만 어떻게 대체 할 수있는 두 foreachs?
봐 [이 스레드의 중복을 –
을 : 유일한 차이점은 내 눈 청소기, (마지막으로 더 라인 데의 비용으로) 줄에 하나의 작업을하는 것입니다 ] (https://stackoverflow.com/questions/34406744/refactoring-a-nested-foreach-into-java-8-stream) – GuyKhmel