我有如下定义的ViewValue类:
class ViewValue {
private Long id;
private Integer value;
private String description;
private View view;
private Double defaultFeeRate;
// getters and setters for all properties
}
Run Code Online (Sandbox Code Playgroud)
在我的代码中的某处,我需要将ViewValue实例列表转换为包含来自相应ViewValue的id字段值的列表.
我使用foreach循环来做到这一点:
List<Long> toIdsList(List<ViewValue> viewValues) {
List<Long> ids = new ArrayList<Long>();
for (ViewValue viewValue : viewValues) {
ids.add(viewValue.getId());
}
return ids;
Run Code Online (Sandbox Code Playgroud)
}
有没有更好的方法来解决这个问题?