使用流迭代列表时获取索引
2022-09-03 14:22:10
List<Rate> rateList =
guestList.stream()
.map(guest -> buildRate(ageRate, guestRate, guest))
.collect(Collectors.toList());
class Rate {
protected int index;
protected AgeRate ageRate;
protected GuestRate guestRate;
protected int age;
}
在上面的代码中,是否可以传递内部方法的索引。我需要在构建时传递索引,但无法设法使用.guestList
buildRate
Rate
Stream