用Java中的responseEentity过滤列表

问题描述

我需要过滤带有响应的列表

   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"
    }
    

解决方法

您正在尝试将StringList<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()))
    ...

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...