Depends on where you want to increment.
Either
userList.stream()
.map(user -> {
counter.getAndIncrement();
return new Foo(getName(user), getId(user));
})
.forEach(fooList::add);
or
userList.stream()
.map(user -> new Foo(getName(user), getId(user)))
.forEach(foo -> {
fooList.add(foo);
counter.getAndIncrement();
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…