title: How to extract all elements of a specific property in a list?
body: <p>how can I best get all "name" string elements of the following structure:</p>
  
  <pre><code>class Foo {
      List&lt;Bar&gt; bars;
  }
  
  class Bar {
      private String name;
      private int age;
  }
  </code></pre>
  
  <p>My approach would be:</p>
  
  <pre><code>List&lt;String&gt; names = new ArrayList&lt;String&gt;();
  
  for (Bar bar : foo.getBars()) {
      names.add(bar.getName());
  }
  </code></pre>
  
  <p>This might work, but isn't there something in java.<code>Collections</code> where I just can write like this:
  <code>Collections.getAll(foo.getBars(), "name");</code>?</p>