Zum Inhalt springen

Order by before where (ARCH4076)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key java.performance.orderby-before-where · Severity warning · Category performance

Sorting before filtering also sorts elements that will be discarded. Filter first to shrink the set that has to be sorted.

return orders.stream()
.sorted(comparing(Order::getDate))
.filter(Order::isActive)
.collect(toList());
return orders.stream()
.filter(Order::isActive)
.sorted(comparing(Order::getDate))
.collect(toList());

Move the sort after the filter so only the needed elements are sorted.