I have one List of elements . Inside the list element in my case say Bean
i have another list . My requirement is like , While iterating over the parent list i have to check for a specific condition in the list obtained from Bean class getList()
and have to return a boolean from there . Below is a demo of code what i want to achieve . How to achieve this in JAVA -8 using lambda .?
public boolean test(List<Bean> parentList) {
//Bean is having another List of Bean1
// i want to do some thing like below
parentList.forEach(bean ->
bean.getList().stream().
filter(somePredicate).
findFirst().isPresent();
}
You should use Stream::flatMap
and check your condition:
parentList.stream().flatMap(bean -> bean.getList().stream()).anyMatch(somePredicate);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With