title: Java - map a list of objects to a list with values of their property attributes
body: <p>I have the ViewValue class defined as follows:</p>
  
  <pre><code>class ViewValue {
  
  private Long id;
  private Integer value;
  private String description;
  private View view;
  private Double defaultFeeRate;
  
  // getters and setters for all properties
  }
  </code></pre>
  
  <p>Somewhere in my code i need to convert a list of ViewValue instances to a list containing values of id fields from corresponding ViewValue.</p>
  
  <p>I do it using foreach loop:</p>
  
  <pre><code>List&lt;Long&gt; toIdsList(List&lt;ViewValue&gt; viewValues) {
  
     List&lt;Long&gt; ids = new ArrayList&lt;Long&gt;();
  
     for (ViewValue viewValue : viewValues) {
        ids.add(viewValue.getId());
     }
  
     return ids;
  </code></pre>
  
  <p>}</p>
  
  <p>Is there a better approach to this problem? </p>