frequency

inline fun <T> Iterable<T>.frequency(element: T): Int(source)

Returns the number of elements in the specified iterable that equal the specified object. This implementation avoids a full iteration when the iterable is a Multiset or Set.

Java 8 users: In most cases, the Stream equivalent of this method is stream.filter(element::equals).count(). If element might be null, use stream.filter(Predicate.isEqual(element)).count() instead.

See also


inline fun <T> Iterator<T>.frequency(element: T): Int(source)

Returns the number of elements in the specified iterator that equal the specified object. The iterator will be left exhausted: its hasNext method will return false.

See also