Java Collection Count count(Collection ts, T toCount)

Here you can find the source of count(Collection ts, T toCount)

Description

count

License

BSD License

Declaration

public static <T> int count(Collection<T> ts, T toCount) 

Method Source Code


//package com.java2s;
//License from project: BSD License 

import java.util.*;

public class Main {
    public static <T> int count(Collection<T> ts, T toCount) {
        int out = 0;
        for (T t : ts)
            if (t.equals(toCount))
                out++;/*from   w  w  w  .jav  a 2s.  c om*/
        return out;
    }

    public static <T> int count(T[] ts, T toCount) {
        int out = 0;
        for (T t : ts)
            if (t.equals(toCount))
                out++;
        return out;
    }

    public static int count(int[] is, int toCount) {
        int out = 0;
        for (int i : is)
            if (i == toCount)
                out++;
        return out;
    }

    public static int count(long[] ls, long toCount) {
        int out = 0;
        for (long l : ls)
            if (l == toCount)
                out++;
        return out;
    }
}

Related

  1. count(Collection collection)
  2. count(Collection collection)
  3. count(final Collection collection, final ItemType item)
  4. count(final Collection blocks)
  5. count(T x0, T x1, T x2, Collection sentences)
  6. count(V matching, Collection values)