问题描述
我需要过滤带有响应的列表
ResponseEntity<Gruoup> listaGrupo = monstarListaGrupo(login,token);
List<Diretorio> diretorios = lista.stream()
.filter(x-> x.getGrupoAd() == listaGrupo.getBody().getGrupos())
我试图那样做,但他不接受,因为它说一种类型是列表,另一种类型是字符串
考试年龄列表中RespondeEntity的公寓过滤器
RespondeEntity:
{
"name": "barry","age": 20
},{
"name": "allan","age": 17
},{
"name": "julie",{
"name": "jord","age": 19
}
列表:
{
"name": "jhenny","age": 20,"color": "red"
},{
"name": "barry","color": "black"
},"color": "white"
}
最终结果列表
{
"name": "barry","color": "white"
}
解决方法
您正在尝试将String
与List<Grupo>
进行比较,但是您似乎想基于包含Directio的grupoAd的响应实体进行过滤。
首先将列表中的字符串收集到集合中,然后使用contains()
作为过滤器,如下所示:
ResponseEntity<Gruoup> listaGrupo = monstarListaGrupo(login,token);
Set<String> names = listaGrupo.getBody().getGrupos().stream().collect(toSet());
List<Diretorio> diretorios = lista.stream()
.filter(x -> names.contains(x.getGrupoAd()))
...