I have
List<String, Person> generalList
as a list. there is Customer object Under Person, 1 more list under Customer named Id
I want to filter this nested IdList under object but it is not working.
I tried to use flatMap but this code is not working
String s = generalList.stream()
.flatMap(a -> a.getCustomer().getIdList().stream())
.filter(b -> b.getValue().equals("1"))
.findFirst()
.orElse(null);
I expect the output as String or Customer object
Edit: My original container is a map, I am filtering Map to List
Explanation.
Map<String, List<Person> container;
List<Person> list = container.get("A");
String s = list.stream()
.flatMap(a -> a.getCustomer().getIdList().stream())
.filter(b -> b.getValue().equals("1"))
.findFirst()
.orElse(null);
Here is the Person
public class Person
{
private Customer customer;
public Customer getCustomer ()
{
return customer;
}
}
And Customer
public class Customer {
private Id[] idList;
/*getter setter*/
}
And Id
public class Id {
private String value;
/*getter setter*/
}
List<String, Object>do you mean aMap?List<Person>where Person is POJO class