How to add index to the function used in the map - java 8.
Currently I am doing :
final int[] position = { 0 };
List<Apple> Apples = request.getOranges().stream()
.map(c -> {
return Converter.fromOranges(c, position[0]++);
}).collect(Collectors.toList());
public static Apple fromOranges(Orange orange, int position) {
Apple Apple = new Apple().builder()
.AppleId(orange.getId())
.position(orange.isPositioned() ? position : null )
.build();
return Apple;
}
Can someone tell me a better way of doing this. I need the index to be sent for the position ( request.getOranges() is a list - position is just the index in the list)