I have a code like this:
List Listings = new ArrayList<>();
Listings.add(listing1);
Listings.add(listing2);
...
...
...
Listing listing= li
filter
itself without a terminal operation would have a zero overhead - as it does absolutely nothing; streams are driven by the terminal operation only - no terminal operation, nothing gets executed.
Then comes the case that filter
has to iterate over all elements (potentially all) of the source (lazily). So time complexity of filter will depend on the source that you Stream from; in your case List
, so it would be O(n)
.
But that would be the worst case. You can't predicate the average case as far as I can see for filter
in general because it depends on the underlying source.