I'm trying to migrate a function from java 7 to java8 but i'm stucked over getting the value of the indexed element while looping a list. What is the good way to do this ?
here is the code that i'm trying to migrate:
List<Employe> listEmploye = new ArrayList<>();
for(int i=0; i< ids.size();i++)
{
Long idLong = Long.valueOf(ids.get(i));
BigDecimal idBig= BigDecimal.valueOf(idLong);
listEmploye.add(findByIdPointage(idBig));
}
Obtain an iterator to the start of the collection by calling the collection's iterator() method. Set up a loop that makes a call to hasNext(). Have the loop iterate as long as hasNext() returns true. Within the loop, obtain each element by calling next().
You can use Stream API to map your collection:
List<Employe> listEmploye = ids.stream()
.map(Long::valueOf)
.map(BigDecimal::valueOf)
.map(this::findByIdPointage)
.collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With