How to Browse a List With Map and Array List Within the Same List (JAVA)Springboot

Asked

Viewed 19 times

-2

Hierarquia do List

I need to go through this List (List) however I cannot, I need to pass the value "options",take the value "option_Id", and go through the option_value and bring the option_value_id and Name

in short, it is a list, with a Map, inside the Map has an Arraylist with another Arraylist and I need to reach the last layer to take this data and store in a MAP

Meu Codigo bold text

1 answer

0

I managed to solve, it was something absurd so somples, follows below the answer in Print

inserir a descrição da imagem aqui

Below the Code of the Complacent Method

 public List<Map> ListarOptions() {
    Map configAlternativa = spiritShopRepository.getConfig(1);
    String url = url_base + "/options";
    Map header = new HashMap();
    header.put("key", util.toStr(configAlternativa.get("SECRET_KEY")));
    List listOptions = restUtil.get(url, header);//passar o Headers


    List lista = new ArrayList();
    lista.add(listOptions.get(0));
    Map option = (Map) lista.get(0);

    List<Map> mapOptions = (List<Map>) option.get("options");

    List<Map> cores = new ArrayList<>();
    List<Map> tamanhos = new ArrayList<>();
    for (Map map : mapOptions) {
        String nome = (String) map.get("name");
        if (nome.equals("Cor") ||
                nome.equals("COR") ||
                nome.equals("cor") ||
                nome.equals("Cores") ||
                nome.equals("CORES") ||
                nome.equals("cores")) {
            cores = (List<Map>) map.get("options_value");
        }
        if (nome.equals("Tamanho") ||
                nome.equals("TAMANHO") ||
                nome.equals("tamanho") ||
                nome.equals("Numeração") ||
                nome.equals("NUMERAÇÃO") ||
                nome.equals("numeração") ||
                nome.equals("Numeracao") ||
                nome.equals("numeracao") ||
                nome.equals("Grade") ||
                nome.equals("GRADE") ||
                nome.equals("grade") ||
                nome.equals("Grades") ||
                nome.equals("GRADES") ||
                nome.equals("grades")) {
            tamanhos = (List<Map>) map.get("options_value");
        }
        System.out.println(nome);
        System.out.println(cores);
        System.out.println(tamanhos);
    }


    System.out.println(lista);


    return listOptions;


}
  • Please provide Additional Details in your Answer. As it’s Currently Written, it’s hard to understand your Solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.