public Stream<T> sort(final Comparator<T> comparator) {
        return new Stream<T>() {
            @Override
            public Iterator<T> iterator() {
                final ArrayList<T> array = ToArrayList.<T>toArrayList().call(Stream.this);
                Collections.sort(array, comparator);
                return array.iterator();
            }
        };
    }
public Stream < T > sort ( final Comparator < T > comparator ) { return new Stream < T > ( ) { @ Override public Iterator < T > iterator ( ) { final ArrayList < T > array = ToArrayList . < T > toArrayList ( ) . call ( Stream . this ) ; Collections . sort ( array , comparator ) ; return array . iterator ( ) ; } } ; }
Returns a new stream that contains all items of the current stream in sorted order.
The operator creates a list of all items internally.

@param comparator a comparator to apply.
@return a new stream that contains all items of the current stream in sorted order.