示例JSON
[
{
"id": "1",
"products": [
{
"id": "333",
"status": "Active"
},
{
"id": "222",
"status": "Inactive"
},
{
"id": "111",
"status": "Active"
}
]
},
{
"id": "2",
"products": [
{
"id": "6",
"status": "Active"
},
{
"id": "7",
"status": "Inactive"
}
]
}
]
我希望能够检索到至少有一个活动产品的对象列表。
下面的代码返回产品列表,但我想要一个ProdcutResponse
列表。有什么方法可以做到这一点吗?
response.stream()
.map(ProductResponse::getProducts)
.filter(s -> "Active".equals(s.getType()))
.collect(Collectors.toList())
O(n^2)
。需要进行一些预计算以进行优化。 - Jacob G.