title: How do Java stream methods operate?
body: <p>I just about understand Java streams. One can create a stream by calling .stream() on a Collection, and then you can operate on that stream with methods as described by the <a href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html" rel="nofollow noreferrer">docs</a>.</p>
  <p>What I don't understand is where the process actually occurs. What I mean by that is sure I can create a stream of Person objects with an age attribute and sort it like so:</p>
  <pre><code>Person john = new Person(30);
  Person anne = new Person(25);
  Person bill = new Person(52);
  
  ArrayList&lt;Person&gt; people = new ArrayList&lt;Person&gt;();
  people.add(john);
  people.add(anne);
  people.add(bill);
  
  ArrayList&lt;Person&gt; sortedPeople = people
  .stream()
  .sorted(Comparators.comparing(person -&gt; person.getAge()))
  .collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
  </code></pre>
  <p>But in the docs and the source code I have found, functional interfaces like the one containing the sorted method has no sorting code and just describes the lambda function passed to it.
  Have I massively misunderstood something here?</p>