filterOrderedBy()
Filter the input stream so that it contains elements the order specified as measured by the given
Comparator
.Implementation Notes
This is suitable for streams whose elements do not implement Comparable
. For a version that uses the natural order of
elements that implement Comparable
, see filterOrdered()
.
Signature
filterOrderedBy(Order order, Comparator<INPUT> comparator)
order
- A non-null Order in which to filter elements. Values areEqual
,Ascending
,Descending
,AscendingOrEqual
, andDescendingOrEqual
comparator
- A non-nullComparator
to compare stream elements
Examples
Filter the stream such that it is strictly descending, according to the given Comparator
Stream
.of("AAA", "AA", "AA", "AAA", "A");
.gather(Gatherers4j.filterOrderedBy(Order.Descending, Comparator.comparingInt(String::length)))
.toList();
// ["AAA", "AA", "A"];