In the question What does it mean :: in java? it explains what they mean the ::
.
Basically, in java 8 now the methods can be sent as parameters. The object listaDao
is of type Iterable<PersonEntity>
. The method map
iterates over each element of the object listadoDao
to convert them to type PersonModel
.
The subject of the method map
in this case is PersonModel map(Function<PersonEntity> p)
and as dictates the use of lambdas, to be able to send a method as a parameter, this method must have the same subject and the method personEntityToPersonModel
satisfies that condition.
In summary, the method personEntityToPersonModel
will be executed for each element that has iterator listaDao
. That code can be translated with lambdas in the following way:
listModels.addAll(listaDao.stream().map(personEntity->{
// codigo del metodo personEntityToPersonModel
}).collect(Collectors.toList()));
And it would work in the same way. The only thing that in your case is sent the method as a parameter instead of defining a lambda.
And finally .collect(Collectors.toList())
convert the resulting Stream to List<PersonModel>
.