Java Collection Count countComplement(Collection s1, Collection s2)

Here you can find the source of countComplement(Collection s1, Collection s2)

Description

count Complement

License

Open Source License

Declaration

public static <T extends Object> int countComplement(Collection<? extends T> s1, Collection<? extends T> s2) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    public static <T extends Object> int countComplement(Collection<? extends T> s1, Collection<? extends T> s2) {
        int n1 = s1.size();
        int n2 = s2.size();
        if (n2 < n1) {
            Collection<? extends T> t = s1;
            s1 = s2;/*from  w w  w .j av  a2  s.  com*/
            s2 = t;
        }
        int n = s2.size() - s1.size();
        for (T e : s1) {
            if (!s2.contains(e))
                n++;
        }
        return n;
    }

    public static int size(Collection<?> c) {
        return (c == null) ? 0 : c.size();
    }
}

Related

  1. count(final Collection collection, final ItemType item)
  2. count(final Collection blocks)
  3. count(T x0, T x1, T x2, Collection sentences)
  4. count(V matching, Collection values)
  5. countCollectionsSize(Collection... cols)
  6. countDuplicates(Collection items)
  7. countOverlappers(Collection distances)