Java Streams: distinct() on a pre
As discussed in this question, the implementation of distinct()
is able to use a more efficient algorithm when the stream it operates on is known by the runtime to be sorted. How can we achieve a similar result if we know that the stream is sorted (eg because it came from an externally pre-sorted data source, such as an SQL query with an order by
clause) but isn't flagged as such? There's an unordered()
operation that removes the ordering flags, but as far as I can see no way of telling the system that the data has been ordered externally.
您可以围绕现有的集合创建分割器,例如:
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
链接地址: http://www.djcxy.com/p/40446.html
上一篇: 如何重用Angular项目的构建