Java tutorial
//package com.java2s; import java.util.Collection; public class Main { static int total = 0; public static int Cardinality(Object obj, Collection coll) { if (coll == null) { throw new NullPointerException(); } if (obj == null) { throw new NullPointerException(); } for (Object o : coll) { if (o.equals(obj)) { total++; } } return total; } }