title: Java 8 - sort a Collection of Objects by a property with an order defined in an array
body: <p>Let's say I have the following Class:</p>
  
  <pre><code>public class Foo {
      private int id;
      private String name;
  
      public int getId() {
          return id;
      }
  
      public Foo setId(int id) {
          this.id = id;
          return this;
      }
  
      public String getName() {
          return name;
      }
  
      public Foo setName(String name) {
          this.name = name;
          return this;
      }
  }
  </code></pre>
  
  <p>Then, I have a couple of <code>Foo</code> objects in <code>Collection&lt;Foo&gt; fooCollection</code> and the String Array <code>String[] names</code>.</p>
  
  <p>Now I want to order <code>fooCollection</code> by the property <code>name</code>, in the same order the <code>name</code> Strings are ordered in <code>names</code>.</p>
  
  <p>How do I do that using Java 8 Stream?</p>