performance - Java Streams: distinct() on a pre-sorted stream? -


as discussed in this question, implementation of distinct() able use more efficient algorithm when stream operates on known runtime sorted. how can achieve similar result if we know stream sorted (e.g. because came externally pre-sorted data source, such sql query order by clause) isn't flagged such? there's unordered() operation removes ordering flags, far can see no way of telling system data has been ordered externally.

you create spliterator around existing collection example:

    list<integer> list = arrays.aslist(1, 2, 3, 4);      spliterator<integer> sp = spliterators.spliterator(list, spliterator.sorted);      system.out.println(sp.hascharacteristics(spliterator.sorted)); // true 

Comments

Popular posts from this blog

php - Embed BBCode within itself not working -

minify - Minimizing css files -

Connecting Spring Batch to Remote Cassandra Database -