How to loop list object and getting it's element by index?

  • A+

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)); } 


You can use Stream API to map your collection:

List<Employe> listEmploye  = .map(Long::valueOf) .map(BigDecimal::valueOf) .map(this::findByIdPointage) .collect(Collectors.toList()); 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: