There is a list of View2
object, I want to add the Id
of View2
object in List<Integer> Ids
. I want to process the above operation in a single line of code.
class View1{
List<Integer> Ids;
}
class View2{
Integer Id;
}
List<View2> views2 = getViews()
Want to something like following.
view1.setIds(view2.forEach(s -> s.getId()));
尝试这个
view1.setIds(view2.stream().map(View2::getId).collect(Collectors.toList()));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.