title: How to sort list based on nested object property
body: <p>I am new to Java streams and I just want to sort the keys for my object.</p>
  
  <p>So, I try something like this and it works</p>
  
  <pre><code>List&lt;FooSelect&gt; li= Arrays.stream(obj.getFoos().getFoo())  //Stream&lt;Foo&gt;
      .map(Foo::getSelect)                                   //Stream&lt;FooSelect&gt;
      .sorted(Comparator.comparing(FooSelect::getFoosKey))   //Stream&lt;FooSelect&gt;
      .collect(Collectors.toList());
  </code></pre>
  
  <p>This sorts it according to what I want.</p>
  
  <p>But the result I get is in <code>List&lt;FooSelect&gt;</code> object, though I want it in <code>List&lt;Foo&gt;</code>.</p>
  
  <p>How can I change the mapping after it is sorted?</p>
  
  <p>I want to again change the response in </p>
  
  <pre><code>//Stream&lt;Foo&gt; after it is sorted.
  </code></pre>
  
  <p>I want something like</p>
  
  <pre><code>List&lt;Foo&gt; li = same result of code above;
  </code></pre>
  
  <hr>
  
  <pre><code>Class : FooSelect
  just has some String fields
  string FooKey
  string FooTKey
  </code></pre>
  
  <p>and getters and setters for that (one of them is getFoosKey by which I am sorting)</p>
  
  <pre><code>Class: Foo
  private FooSelect select
  private FooInsert insert
  
  Foo(select, insert)
  
  public FooSelect getSelect() {
  return select; }
  </code></pre>
  
  <p>Same way setter.</p>