filter().isEmpty
with !exists()
SC-R1007filter()
allows you to select elements from your collection that satisfy the provided condition/predicate. In situations where you need to check if there are any elements satisfying your condition, it is suggested that you directly use !exists()
over filter().isEmpty
as the former is slightly more efficient, readable, and easy to maintain.
// count even numbers
nums.filter(n => n % 2 == 0).isEmpty // get's the job done
!nums.exists(n => n % 2 == 0) // that's better