Java 8 streams: determining if members of a list are "equal"
<p>I am trying to make a very concise way (using streams, of course) to determine if two members of a collection (a list) are equal. But not equal in the sense of the method <code>equals()</code> but using a different method for comparing.</p>

<p>Basically, I have a list of timeslots, and these define an order. You can say if a timeslot precedes, passes or is equal to another using the <code>Timeslot#compareTo(Timeslot)</code> method. I need these timeslots to be in order, that is, every one of them precedes the following in the list, but I also need each one of them to be strictly greater than the next one. They cannot be equal (you cannot have <code>timeslot1=10am</code> and then <code>timeslot2=10am</code>).</p>

<p>I got the ordering covered, as easy as this:</p>

<pre><code>Collections.sort(timeslots, Timeslot::compareTo);
</code></pre>

<p>However, I would like to be very concise when determining if every timeslot strictly precedes the following or not. Of course, I could do this the traditional way as follows:</p>

<pre><code>for (int i = 0; i &lt; timeslots.size() - 1; i++)
    if (timeslots.get(i).compareTo(timeslots.get(i + 1)) == 0)
        throw new IllegalArgumentException("Every timeslot must strictly precede the following");
</code></pre>

<p>Maybe I am asking too much of streams, and there is really no better and equally efficient way of achieving this, but I would be glad to hear out your ideas.</p>