【发布时间】:2021-12-02 15:40:43
【问题描述】:
我有一个简单的课程:
class Note {
public int id;
public String status;
// some other fields....
}
我想通过流 api 映射此类的字段。我有一个简单的方法实现,可以做我想要的:
public function(int externalId) {
Set<Note> notes = getFromRepository(); // simple method for getting all Note from repository
for (Note note : notes){
note.setId(externalId);
note.setStatus("Open");
}
}
如何使用 Stream api 做到这一点?
【问题讨论】: