title: Java 8 Stream - .max() with duplicates
body: <p>So I have a collection of objects that have a step variable that can be 1 - 4.</p>
  
  <pre><code>public class MyClass {
      private Long step;
  
      //other variables, getters, setters, etc.
  }
  </code></pre>
  
  <p><code>Collection&lt;MyClass&gt; myOjbects = /*get collection*/;</code></p>
  
  <p>Then I would like to get one instance of <code>MyClass</code> from the collection that has the maximum step value, so I do:</p>
  
  <pre><code>final Optional&lt;MyClass&gt; objectWithMaxStep =
     myObjects.stream().max(Comparator.comparing(MyClass::getStep));
  </code></pre>
  
  <p>However, there are situations where there will be multiple <code>MyClass</code> instances in the collection that have a step equal to 4. </p>
  
  <p>So, my question is, how is it determined which instance is returned in the <code>Optional</code>, or does it throw an exception when multiple objects in the stream have the max value that is being compared?</p>
  
  <p>The Java 8 documentation for the <code>max()</code> function does not specify what will occur in this situation.</p>