Java Utililty Methods Collection Count

List of utility methods to do Collection Count

Description

The list of methods to do Collection Count are organized into topic(s).

Method

intcount(Collection collection)
count
if (isEmpty(collection))
    return 0;
return collection.size();
Mapcount(Collection collection)
Returns a map where each entry represents the number of times that the corresponding key appears in the input collection.
Map<A, Integer> out = new LinkedHashMap<A, Integer>();
for (A value : collection)
    out.put(value, out.containsKey(value) ? out.get(value) + 1 : 1);
return out;
intcount(Collection ts, T toCount)
count
int out = 0;
for (T t : ts)
    if (t.equals(toCount))
        out++;
return out;
intcount(final Collection collection, final ItemType item)
count
int counter = 0;
for (final ItemType itemType : collection) {
    if (itemType == item) {
        counter++;
return counter;
longcount(final Collection blocks)
TODO
if (blocks == null || blocks.isEmpty()) {
    return 0L;
return blocks.stream().mapToLong(block -> block.length).sum();
Doublecount(T x0, T x1, T x2, Collection sentences)
count
Double count = 0d;
for (T[] sentence : sentences) {
    int idx0 = contains(sentence, x0);
    if (idx0 >= 0) {
        if (idx0 + 2 < sentence.length && x1.equals(sentence[idx0 + 1]) && x2.equals(sentence[idx0 + 2])) {
            count++;
return count;
intcount(V matching, Collection values)
count
int count = 0;
for (V value : values) {
    if (matching.equals(value)) {
        count++;
return count;
intcountCollectionsSize(Collection... cols)
count Collections Size
int totalSize = 0;
if (cols == null || cols.length < 1)
    return totalSize;
for (Collection oneList : cols) {
    if (oneList == null)
        continue;
    totalSize += oneList.size();
return totalSize;
intcountComplement(Collection s1, Collection s2)
count Complement
int n1 = s1.size();
int n2 = s2.size();
if (n2 < n1) {
    Collection<? extends T> t = s1;
    s1 = s2;
    s2 = t;
int n = s2.size() - s1.size();
...
ListcountDuplicates(Collection items)
count Duplicates
List<T> itemSet = new ArrayList<T>();
for (T item : items) {
    if (!itemSet.contains(item)) {
        itemSet.add(item);
Object[] params = new Object[itemSet.size()];
int n = 0;
...