Java - map a list of objects to a list with values of their property attributes

后端 未结 8 1800
星月不相逢
星月不相逢 2020-12-01 01:28

I have the ViewValue class defined as follows:

class ViewValue {

private Long id;
private Integer value;
private String description;
private View view;
priv         


        
8条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 01:55

    We can do it in a single line of code using java 8

    List ids = viewValues.stream().map(ViewValue::getId).collect(Collectors.toList());
    

    For more info : Java 8 - Streams

提交回复
热议问题