1
Good afternoon, I have a list of Pessoa
where class is like this:
public class Pessoa {
private String nome;
private String idade;
}
I set up the list like this:
List<Pessoa> pessoas = new ArrayList<>();
pessoas.add(new Pessoa("Douglas","30"));
pessoas.add(new Pessoa("Leonardo","30"));
pessoas.add(new Pessoa("Douglas","35"));
The list has 3 elements, I need to get the elements whose attribute idade
is repeating, deleting one of the elements and in the field nome
I will concatenate with comma nome
of the excluded element thus:
[Pessoa{nome='Douglas,Leonardo', idade='30'}, Pessoa{nome='Douglas', idade='35'}]
It is possible to do with a single lambda instruction?
It is not possible to do with a single lambda function as it is a two-step task: 1-sort the data into one Hashmap to know the repeated elements. 2 - Organize the classified elements in the desired data structure. It will take at least two anonymous functions.
– Augusto Vasques