Nested lists with streams in Java8

前端 未结 4 1259
感动是毒
感动是毒 2020-12-05 23:42

I have a list of objects A. Each object A in this list contains list of object B and the object B contains list of Object C. The object C contains an attribute name that i w

4条回答
  •  -上瘾入骨i
    2020-12-06 00:33

     listOfObjectsA.stream()
                   .flatMap(a -> a.getListOfObjectsB.stream())
                   .flatMap(b -> b.getListOfObjectsC().stream())
                   .filter(c -> name.equals(c.getName()))
                   .findAny()
                   .orElse(....)
    

提交回复
热议问题