8000 Implement count(Predicate<T>) · Issue #260 · amaembo/streamex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Implement count(Predicate<T>) #260
Closed
@Suicolen

Description

@Suicolen

I believe it is somewhat common to filter a stream and count the number of elements, for example to count the number of even numbers in a range u would write:
long evenCount = IntStreamEx.range(n).filter(x -> x % 2 == 0).count();
However a count method that takes in a Predicate and only counts the element if it matches the predicate would be more convenient imo.
Example:
long evenCount = IntStreamEx.range(n).count(x -> x % 2 == 0);

Alternatively the method could be called countIf

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0